@@ -19,7 +19,9 @@ public void testHandleStyleNodeExceptions() throws Exception {
1919 "url (' ')" ,
2020 "url('\" )" ,
2121 "url(')" ,
22- "url('\" ')"
22+ "url('\" ')" ,
23+ "url('\\ \" \" ')" ,
24+ "url(''''')"
2325 };
2426 boolean except = false ;
2527 HTMLMetaData md = new HTMLMetaData (new MetaData ());
@@ -37,6 +39,7 @@ public void testHandleStyleNodeExceptions() throws Exception {
3739 assertFalse (except );
3840 }
3941 }
42+
4043 public void testHandleStyleNode () throws Exception {
4144 String [][] tests = {
4245 {"" },
@@ -45,31 +48,36 @@ public void testHandleStyleNode() throws Exception {
4548 {"url(\" foo.gif\" )" ,"foo.gif" },
4649 {"url(\\ \" foo.gif\\ \" )" ,"foo.gif" },
4750 {"url(\\ 'foo.gif\\ ')" ,"foo.gif" },
48-
49- };
51+ {"url(''foo.gif'')" ,"foo.gif" },
52+ {"url( foo.gif )" ,"foo.gif" },
53+ {"url('''')" },
54+ {"url('foo.gif'')" ,"foo.gif" },
55+ };
5056 for (String [] testa : tests ) {
5157 checkExtract (testa );
5258 }
53- // boolean except = false;
54- // HTMLMetaData md = new HTMLMetaData(new MetaData());
55- // ExtractingParseObserver epo = new ExtractingParseObserver(md);
56- // for(String css : tests) {
57- // try {
58- // TextNode tn = new TextNode(css);
59- // epo.handleStyleNode(tn);
60- // } catch(Exception e) {
61- // System.err.format("And the winner is....(%s)\n", css);
62- // e.printStackTrace();
63- // except = true;
64- // throw e;
65- // }
66- // assertFalse(except);
67- // }
6859 }
60+
61+ /**
62+ * Test whether the pattern matcher does extract nothing and also does not
63+ * not hang-up if an overlong CSS link is truncated.
64+ */
65+ public void testHandleStyleNodeNoHangupTruncated () throws Exception {
66+ StringBuilder sb = new StringBuilder ();
67+ sb .append ("url(" );
68+ for (int i = 0 ; i < 500000 ; i ++)
69+ sb .append ('\'' );
70+ sb .append ("foo.gif" );
71+ for (int i = 0 ; i < 499000 ; i ++)
72+ sb .append ('\'' );
73+ String [] test = new String [1 ];
74+ test [0 ] = sb .toString ();
75+ checkExtract (test );
76+ }
77+
6978 private void checkExtract (String [] data ) throws JSONException {
7079// System.err.format("CSS(%s) want[0](%s)\n",css,want[0]);
7180 String css = data [0 ];
72- boolean except = false ;
7381 HTMLMetaData md = new HTMLMetaData (new MetaData ());
7482 ExtractingParseObserver epo = new ExtractingParseObserver (md );
7583 try {
@@ -87,10 +95,11 @@ private void checkExtract(String[] data) throws JSONException {
8795
8896 assertTrue (o instanceof JSONObject );
8997 JSONObject jo = (JSONObject ) o ;
90- assertEquals (data [i ],jo .getString ("href" ));
98+ assertEquals ("CSS link extraction failed for <" + css + ">" ,
99+ data [i ], jo .getString ("href" ));
91100 }
92101 } else {
93- assertNull (a );
102+ assertNull ("Expected no extracted link for <" + css + ">" , a );
94103 }
95104 }
96105
0 commit comments