Skip to content

Commit 567bd21

Browse files
vaadin-botcaalador
andauthored
fix: Do not decode + as space (#12432) (#12466)
Fix issue with URLDecoder handling of '+' character. Fixes #12354 Co-authored-by: caalador <mikael.grankvist@vaadin.com>
1 parent b066ce5 commit 567bd21

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/router/QueryParameters.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static List<String> makeQueryParamList(String paramAndValue) {
130130
return Collections.singletonList(paramAndValue);
131131
}
132132
String param = paramAndValue.substring(0, index);
133-
String value = paramAndValue.substring(index + 1);
133+
String value = paramAndValue.substring(index + 1).replace("+", "%2B");
134134
try {
135135
value = URLDecoder.decode(value, "utf-8");
136136
} catch (UnsupportedEncodingException e) {

‎flow-server/src/test/java/com/vaadin/flow/router/LocationTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ public void locationFromSegments() {
110110
assertEquals("one/two", location.getPath());
111111
}
112112

113+
@Test
114+
public void queryValue_decodedCorrectly() {
115+
Location location = new Location("home?value+part");
116+
Assert.assertEquals("'+' should not be decoded to space", "value+part",
117+
location.getQueryParameters().getQueryString());
118+
119+
location = new Location("home?someValue1%2BsomeValue2");
120+
Assert.assertEquals("'+' should not be double decoded",
121+
"someValue1+someValue2",
122+
location.getQueryParameters().getQueryString());
123+
}
124+
113125
@Test
114126
public void subLocation() {
115127
Location location = new Location(Arrays.asList("one", "two", "three"));

‎flow-server/src/test/java/com/vaadin/flow/router/QueryParametersTest.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

3333
public class QueryParametersTest {
3434

35-
private String simpleInputQueryString = "one=1&two=2&three=3&four&five=4%2F5%266%2B7";
35+
private String simpleInputQueryString = "one=1&two=2&three=3&four&five=4%2F5%266%2B7&six=val+ue";
3636

37-
private String complexInputQueryString = "one=1&one=11&two=2&two=22&three=3&four&five=4%2F5%266%2B7";
37+
private String complexInputQueryString = "one=1&one=11&two=2&two=22&three=3&four&five=4%2F5%266%2B7&six=val+ue";
3838

3939
private Map<String, String> getSimpleInputParameters() {
4040
Map<String, String> inputParameters = new HashMap<>();
@@ -106,6 +106,7 @@ public void simpleParametersFromQueryString() {
106106
expectedFullParams.put("three", Collections.singletonList("3"));
107107
expectedFullParams.put("four", Collections.singletonList(""));
108108
expectedFullParams.put("five", Collections.singletonList("4/5&6+7"));
109+
expectedFullParams.put("six", Collections.singletonList("val+ue"));
109110
assertEquals(expectedFullParams, simpleParams.getParameters());
110111
}
111112

@@ -158,6 +159,7 @@ public void complexParametersFromQueryString() {
158159
expectedFullParams.put("three", Collections.singletonList("3"));
159160
expectedFullParams.put("four", Collections.singletonList(""));
160161
expectedFullParams.put("five", Collections.singletonList("4/5&6+7"));
162+
expectedFullParams.put("six", Collections.singletonList("val+ue"));
161163
assertEquals(expectedFullParams, fullParams.getParameters());
162164
}
163165

0 commit comments

Comments
 (0)