You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2023/02/24 16:38:17 UTC
[wicket] branch wicket-9.x updated: WICKET-7022 added condition to tell if we are inside a regexp
This is an automated email from the ASF dual-hosted git repository.
adelbene pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-9.x by this push:
new 08dcc571aa WICKET-7022 added condition to tell if we are inside a regexp
08dcc571aa is described below
commit 08dcc571aa5d0693d2f75f2959c31f94cd38ac69
Author: Andrea Del Bene <ad...@apache.org>
AuthorDate: Fri Feb 24 17:38:09 2023 +0100
WICKET-7022 added condition to tell if we are inside a regexp
---
.../apache/wicket/core/util/string/JavaScriptStripper.java | 3 ++-
.../wicket/core/util/string/JavaScriptStripperTest.java | 13 +++++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/wicket-core/src/main/java/org/apache/wicket/core/util/string/JavaScriptStripper.java b/wicket-core/src/main/java/org/apache/wicket/core/util/string/JavaScriptStripper.java
index bb57ce7683..8f7e4ae126 100644
--- a/wicket-core/src/main/java/org/apache/wicket/core/util/string/JavaScriptStripper.java
+++ b/wicket-core/src/main/java/org/apache/wicket/core/util/string/JavaScriptStripper.java
@@ -126,6 +126,7 @@ public class JavaScriptStripper
// char, which
// will be either '=' or '('. If it's not, it's just a divide operator.
int idx = result.length() - 1;
+ String trimmedResult = result.toString().trim();
while (idx > 0)
{
char tmp = result.charAt(idx);
@@ -135,7 +136,7 @@ public class JavaScriptStripper
continue;
}
if (tmp == '=' || tmp == '(' || tmp == '{' || tmp == ':' || tmp == ',' ||
- tmp == '[' || tmp == ';' || tmp == '!')
+ tmp == '[' || tmp == ';' || tmp == '!' || trimmedResult.endsWith("return"))
{
state = REG_EXP;
break;
diff --git a/wicket-core/src/test/java/org/apache/wicket/core/util/string/JavaScriptStripperTest.java b/wicket-core/src/test/java/org/apache/wicket/core/util/string/JavaScriptStripperTest.java
index e7df54695d..99d30cb6e6 100644
--- a/wicket-core/src/test/java/org/apache/wicket/core/util/string/JavaScriptStripperTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/core/util/string/JavaScriptStripperTest.java
@@ -16,13 +16,12 @@
*/
package org.apache.wicket.core.util.string;
-import org.apache.wicket.core.util.string.JavaScriptStripper;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+
/**
* Tests {@link JavaScriptStripper}
*
@@ -87,9 +86,15 @@ class JavaScriptStripperTest
String after = new JavaScriptStripper().stripCommentsAndWhitespace(before);
String expected = " attr: \n /\\[((?:[\\w-]*:)?[\\w-]+)\\s*(?:([!^$*~|]?=)\\s*((['\"])([^\\4]*?)\\4|([^'\"][^\\]]*?)))?\\]/ after regex";
assertEquals(expected, after);
- System.out.println(after);
}
+ @Test
+ void regexpDoubleSlash()
+ {
+ String before = "return/[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)/gi.test(t);}}";
+ String after = new JavaScriptStripper().stripCommentsAndWhitespace(before);
+ assertEquals(before, after);
+ }
/** */
@Test
void WICKET1806()