From: <rb...@us...> - 2013-02-02 17:14:16
|
Revision: 8084 http://sourceforge.net/p/htmlunit/code/8084 Author: rbri Date: 2013-02-02 17:14:13 +0000 (Sat, 02 Feb 2013) Log Message: ----------- fixes for handling of empty oneof selector Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 09:49:10 UTC (rev 8083) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2013-02-02 17:14:13 UTC (rev 8084) @@ -522,8 +522,12 @@ // || attribute.startsWith(condition + " ") || attriubte.endsWith(" " + condition) // || attribute.contains(" " + condition + " "); + final int conditionLength = condition.length(); + if (conditionLength < 1) { + return false; + } + final int attribLength = attribute.length(); - final int conditionLength = condition.length(); if (attribLength < conditionLength) { return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 09:49:10 UTC (rev 8083) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2013-02-02 17:14:13 UTC (rev 8084) @@ -443,7 +443,6 @@ loadPageWithAlerts2(html); } - /** * @throws Exception if an error occurs */ @@ -469,10 +468,65 @@ loadPageWithAlerts2(html); } + /** * @throws Exception if an error occurs */ @Test + @Alerts({ "2", "id1", "id2" }) + public void oneOfAttribute() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[title~=\"w2\"]');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " alert(list[1].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='id1' title='w1 w2 w3'></ul>\n" + + " <p id='id2' title='w2'></p>\n" + + " <ul id='id3' title='w1w2 w3'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "0" }) + public void oneOfAttributeEmpty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('[title~=\"\"]');\n" + + " alert(list.length);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='id1' title='w1 w2 w3'></ul>\n" + + " <p id='id2' title='w2'></p>\n" + + " <ul id='id3' title='w1w2 w3'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test @Alerts({ "1", "ul2" }) public void generalAdjacentSelector() throws Exception { final String html = "<html><head><title>First</title>\n" |