File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
main/java/org/openscience/cdk/smarts
test/java/org/openscience/cdk/smarts Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -1573,7 +1573,8 @@ else if (sub2 != null)
15731573 // final check
15741574 boolean finish () {
15751575 // check for unclosed rings, components, and branches
1576- if (numRingOpens != 0 || curComponentId != 0 || !stack .isEmpty ()) {
1576+ if (numRingOpens != 0 || curComponentId != 0 ||
1577+ !stack .isEmpty () || bond != null ) {
15771578 error = "Unclosed ring, component group, or branch" ;
15781579 return false ;
15791580 }
@@ -1805,6 +1806,8 @@ public boolean parse() {
18051806 case '!' :
18061807 case '/' :
18071808 case '\\' :
1809+ if (prev == null )
1810+ return false ;
18081811 unget ();
18091812 if (!parseBondExpr ())
18101813 return false ;
Original file line number Diff line number Diff line change 2222import org .junit .Test ;
2323import org .openscience .cdk .CDKTestCase ;
2424import org .openscience .cdk .interfaces .IChemObjectBuilder ;
25+ import org .openscience .cdk .isomorphism .matchers .Expr ;
2526import org .openscience .cdk .silent .SilentChemObjectBuilder ;
2627import org .openscience .cdk .smarts .Smarts ;
2728
3637 */
3738public class ParserTest extends CDKTestCase {
3839
40+ private static final class InvalidSmarts extends Exception {
41+ public InvalidSmarts (String message ) {
42+ super (message );
43+ }
44+ }
45+
3946 private void parse (String smarts , int flav ) throws Exception {
4047 IChemObjectBuilder builder = SilentChemObjectBuilder .getInstance ();
4148 if (!Smarts .parse (builder .newAtomContainer (), smarts , flav ))
42- throw new Exception (Smarts .getLastErrorMesg ());
49+ throw new InvalidSmarts (Smarts .getLastErrorMesg ());
4350 }
4451
4552 private void parse (String smarts ) throws Exception {
@@ -1505,4 +1512,14 @@ public void atomMaps2() throws Exception {
15051512 parse ("O=C1NCCSc2ccccc12" );
15061513 }
15071514
1515+ @ Test (expected = InvalidSmarts .class )
1516+ public void testBondPrefix () throws Exception {
1517+ parse ("-CCO" );
1518+ }
1519+
1520+ @ Test (expected = InvalidSmarts .class )
1521+ public void trailingBond () throws Exception {
1522+ parse ("CCO-" );
1523+ }
1524+
15081525}
You can’t perform that action at this time.
0 commit comments