|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
[HtmlUnit] SF.net SVN: htmlunit:[5155] trunk/htmlunitRevision: 5155
http://htmlunit.svn.sourceforge.net/htmlunit/?rev=5155&view=rev Author: mguillem Date: 2009-11-05 13:00:23 +0000 (Thu, 05 Nov 2009) Log Message: ----------- JavaScript HtmlUnit RegExp proxy: escape "$" in replacement string for String.replace. Issue 2891013 Modified Paths: -------------- trunk/htmlunit/checkstyle_suppressions.xml trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java Modified: trunk/htmlunit/checkstyle_suppressions.xml =================================================================== --- trunk/htmlunit/checkstyle_suppressions.xml 2009-11-05 11:05:46 UTC (rev 5154) +++ trunk/htmlunit/checkstyle_suppressions.xml 2009-11-05 13:00:23 UTC (rev 5155) @@ -22,7 +22,7 @@ <suppress checks="LineLength" files="BoxObjectTest.java"/> <suppress checks="LineLength" files="HTMLBodyElementTest.java"/> <suppress checks="LineLength" files="GWTSourceTest.java"/> - <suppress checks="LineLength" files="HtmlUnitRegExpProxyTest.java" lines="634"/> + <suppress checks="LineLength" files="HtmlUnitRegExpProxyTest.java" lines="603"/> <suppress checks="MethodLength" files="DefaultElementFactory.java"/> <suppress checks="MethodLength" files="Dojo102Test.java"/> <suppress checks="MethodLength" files="CSSStyleDeclarationTest.java"/> Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2009-11-05 11:05:46 UTC (rev 5154) +++ trunk/htmlunit/src/changes/changes.xml 2009-11-05 13:00:23 UTC (rev 5155) @@ -6,8 +6,11 @@ <body> <release version="2.7" date="?" description="Bugfixes, initial IE8 support, HttpClient 4 migration"> + <action type="fix" dev="mguillem" issue="2891013"> + JavaScript HtmlUnit RegExp proxy: escape "$" in replacement string for String.replace. + </action> <action type="fix" dev="mguillem" issue="2890953"> - JavaScript: replace "$$" by "$" in replacement string for String.replace. + JavaScript HtmlUnit RegExp proxy: replace "$$" by "$" in replacement string for String.replace. </action> <action type="fix" dev="mguillem"> DefaultCredentialsProvider: addCredentials should overwrite previous values. Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java 2009-11-05 11:05:46 UTC (rev 5154) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxy.java 2009-11-05 13:00:23 UTC (rev 5155) @@ -85,6 +85,7 @@ } else if (arg0 instanceof NativeRegExp) { replacement = replacement.replaceAll("\\\\", "\\\\\\\\"); + replacement = replacement.replaceAll("(?<!\\$)\\$(?!\\d)", "\\\\\\$"); try { final NativeRegExp regexp = (NativeRegExp) arg0; final RegExpData reData = new RegExpData(regexp); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java 2009-11-05 11:05:46 UTC (rev 5154) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/regexp/HtmlUnitRegExpProxyTest.java 2009-11-05 13:00:23 UTC (rev 5155) @@ -107,9 +107,8 @@ * Tests if custom patch is still needed. */ @Test - @Browsers(Browser.NONE) public void needCustomFix() { - final WebClient client = new WebClient(); + final WebClient client = getWebClient(); final ContextFactory cf = client.getJavaScriptEngine().getContextFactory(); final Context ctx = cf.enterContext(); try { @@ -137,14 +136,7 @@ @Test @Alerts("123456") public void replaceNormalStringWithRegexpChars() throws Exception { - final String html = "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " alert('123456'.replace('/{\\d+}', ''));\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); + testEvaluate("'123456'.replace('/{\\d+}', '')"); } /** @@ -243,14 +235,7 @@ @Test @Alerts("ab,a") public void match_NotFirstCharacter() throws Exception { - final String html = "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " alert(\"ab\".match(/^(.)[^\\1]$/))\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); + testEvaluate("\"ab\".match(/^(.)[^\\1]$/)"); } /** @@ -306,9 +291,9 @@ + "(\\/|-|\\.)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|" + "(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$/;\n" + " var str = '2001-06-16';\n" - + " alert(regexp.test(str))\n" - + " alert(regexp.test('hello'))\n" - + " alert(regexp.exec(str) != null)\n" + + " alert(regexp.test(str));\n" + + " alert(regexp.test('hello'));\n" + + " alert(regexp.exec(str) != null);\n" + " }\n" + "</script></head><body onload='test()'>\n" + "</body></html>"; @@ -456,15 +441,7 @@ @Test @Alerts("") public void dollarSignAndCurlyBracket() throws Exception { - final String html = "<html><head><title>foo</title><script>\n" - + " function test() {\n" - + " var value = ''.replace(/\\${/g, '');\n" - + " alert(value)\n" - + " }\n" - + "</script></head><body onload='test()'>\n" - + "</body></html>"; - - loadPageWithAlerts2(html); + testEvaluate("''.replace(/\\${/g, '')"); } /** @@ -491,7 +468,7 @@ * @throws Exception if the test fails */ @Test - @Alerts({ "div" }) + @Alerts("div") public void jquerySizzleChunker() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + " var re = /((?:\\((?:\\([^()]+\\)|[^()]+)+\\)|\\[(?:\\[[^[\\]]*\\]|['\"][^'\"]+['\"]|[^[\\]'\"]+)+\\]" @@ -554,8 +531,7 @@ @Test @Alerts("afood$0$7b") public void replace_backReferences() throws Exception { - final String html = "<script>alert('afoob'.replace(/(foo)/g, '$1d$0$7'));</script>"; - loadPageWithAlerts2(html); + testEvaluate("'afoob'.replace(/(foo)/g, '$1d$0$7')"); } /** @@ -565,8 +541,7 @@ @Test @Alerts("I$want$these$periods$to$be$$s") public void replace_backReferences_2() throws Exception { - final String html = buildHtml("alert('I.want.these.periods.to.be.$s'.replace(/\\./g, '$'));"); - loadPageWithAlerts2(html); + testEvaluate("'I.want.these.periods.to.be.$s'.replace(/\\./g, '$')"); } /** @@ -575,9 +550,7 @@ @Test @Alerts("kid\\'s toys") public void escapeQuote() throws Exception { - final String script = "alert(\"kid's toys\".replace(/'/g, \"\\\\'\"))"; - final String html = buildHtml(script); - loadPageWithAlerts2(html); + testEvaluate("\"kid's toys\".replace(/'/g, \"\\\\'\")"); } private String buildHtml(final String script) { @@ -615,7 +588,6 @@ loadPageWithAlerts2(html); } - /** * Regression test for bug 2890953. * @throws Exception if an error occurs @@ -623,10 +595,7 @@ @Test @Alerts("$$x$") public void replaceDollarDollar() throws Exception { - final String script = "alert('x'.replace(/(x)/g, '$$$$x$$'));"; - final String html = buildHtml(script); - - loadPageWithAlerts2(html); + testEvaluate("'x'.replace(/(x)/g, '$$$$x$$')"); } /** @@ -687,4 +656,21 @@ loadPageWithAlerts2(html); } + + /** + * Regression test for bug 2890953. + * @throws Exception if an error occurs + */ + @Test + @Alerts("\\$0") + public void replaceBackslashDollar() throws Exception { + testEvaluate("'$0'.replace(/\\$/g, '\\\\$')"); + } + + private void testEvaluate(final String expression) throws Exception { + final String script = "alert(" + expression + ");"; + final String html = buildHtml(script); + + loadPageWithAlerts2(html); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ HtmlUnit-develop mailing list HtmlUnit-develop@... https://lists.sourceforge.net/lists/listinfo/htmlunit-develop |
| Free embeddable forum powered by Nabble | Forum Help |