You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/05/16 18:45:01 UTC
[struts] branch WW-5309-named-matcher created (now 1df2f0a36)
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a change to branch WW-5309-named-matcher
in repository https://gitbox.apache.org/repos/asf/struts.git
at 1df2f0a36 WW-5309 Supports patterns starting with variable
This branch includes the following new commits:
new 1df2f0a36 WW-5309 Supports patterns starting with variable
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[struts] 01/01: WW-5309 Supports patterns starting with variable
Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-5309-named-matcher
in repository https://gitbox.apache.org/repos/asf/struts.git
commit 1df2f0a365c61c6a662024e5afcb3b059b8f3297
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue May 16 20:44:55 2023 +0200
WW-5309 Supports patterns starting with variable
---
.../xwork2/util/NamedVariablePatternMatcher.java | 4 ++--
.../xwork2/util/NamedVariablePatternMatcherTest.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcher.java b/core/src/main/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcher.java
index 24e5e9b35..027dc4a58 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcher.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcher.java
@@ -87,8 +87,8 @@ public class NamedVariablePatternMatcher implements PatternMatcher<NamedVariable
int s = 0;
while (s < len) {
int e = data.indexOf('{', s);
- if (e < 0 && data.indexOf('}') > -1) {
- throw new IllegalArgumentException("Missing openning '{' in [" + data + "]!");
+ if (e < 0 && data.indexOf('}', s) > -1) {
+ throw new IllegalArgumentException("Missing opening '{' in [" + data + "]!");
}
if (e < 0) {
regex.append(Pattern.quote(data.substring(s)));
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java b/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
index b5eda4f0a..da7f3f021 100644
--- a/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/util/NamedVariablePatternMatcherTest.java
@@ -53,6 +53,26 @@ public class NamedVariablePatternMatcherTest {
assertEquals("bob", pattern.getVariableNames().get(1));
assertTrue(pattern.getPattern().matcher("foostar/jie").matches());
assertFalse(pattern.getPattern().matcher("foo/star/jie").matches());
+
+ pattern = matcher.compilePattern("{urlLocale}/eula_cz");
+ assertEquals("([^/]+)\\Q/eula_cz\\E", pattern.getPattern().pattern());
+ assertEquals("urlLocale", pattern.getVariableNames().get(0));
+ assertTrue(pattern.getPattern().matcher("foostar/eula_cz").matches());
+ assertFalse(pattern.getPattern().matcher("foo/star/eula_cz").matches());
+
+ pattern = matcher.compilePattern("{test1}/path/{test2}");
+ assertEquals("([^/]+)\\Q/path/\\E([^/]+)", pattern.getPattern().pattern());
+ assertEquals("test1", pattern.getVariableNames().get(0));
+ assertEquals("test2", pattern.getVariableNames().get(1));
+ assertTrue(pattern.getPattern().matcher("test1/path/test2").matches());
+ assertFalse(pattern.getPattern().matcher("test/1/path/test2").matches());
+
+ pattern = matcher.compilePattern("path1/{test1}/path2/{test2}");
+ assertEquals("\\Qpath1/\\E([^/]+)\\Q/path2/\\E([^/]+)", pattern.getPattern().pattern());
+ assertEquals("test1", pattern.getVariableNames().get(0));
+ assertEquals("test2", pattern.getVariableNames().get(1));
+ assertTrue(pattern.getPattern().matcher("path1/test1/path2/test2").matches());
+ assertFalse(pattern.getPattern().matcher("path1/test/1/path2/test2").matches());
}
@Test(expected = IllegalArgumentException.class)