Skip to content

Commit 93f6458

Browse files
committed
Test for non-equality after URI normalization
Issue: SPR-16364
1 parent 347c2da commit 93f6458

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ public void fromOpaqueUri() throws URISyntaxException {
128128
assertEquals("Invalid result URI", uri, result.toUri());
129129
}
130130

131-
@Test // SPR-9317
131+
@Test // SPR-9317
132132
public void fromUriEncodedQuery() throws URISyntaxException {
133133
URI uri = new URI("http://www.example.org/?param=aGVsbG9Xb3JsZA%3D%3D");
134134
String fromUri = UriComponentsBuilder.fromUri(uri).build().getQueryParams().get("param").get(0);
@@ -184,7 +184,7 @@ public void fromUriString() {
184184
assertEquals("28", result.getFragment());
185185
}
186186

187-
@Test // SPR-9832
187+
@Test // SPR-9832
188188
public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
189189
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
190190
UriComponents result = UriComponentsBuilder.fromUriString(uri).build();
@@ -193,15 +193,15 @@ public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxExc
193193
assertEquals("1USD=?EUR", result.getQueryParams().getFirst("q"));
194194
}
195195

196-
@Test // SPR-14828
196+
@Test // SPR-14828
197197
public void fromUriStringQueryParamEncodedAndContainingPlus() throws Exception {
198198
String httpUrl = "http://localhost:8080/test/print?value=%EA%B0%80+%EB%82%98";
199199
URI uri = UriComponentsBuilder.fromHttpUrl(httpUrl).build(true).toUri();
200200

201201
assertEquals(httpUrl, uri.toString());
202202
}
203203

204-
@Test // SPR-10779
204+
@Test // SPR-10779
205205
public void fromHttpUrlStringCaseInsesitiveScheme() {
206206
assertEquals("http", UriComponentsBuilder.fromHttpUrl("HTTP://www.google.com").build().getScheme());
207207
assertEquals("https", UriComponentsBuilder.fromHttpUrl("HTTPS://www.google.com").build().getScheme());
@@ -214,8 +214,8 @@ public void fromHttpUrlStringInvalidIPv6Host() throws URISyntaxException {
214214
UriComponentsBuilder.fromHttpUrl("http://[1abc:2abc:3abc::5ABC:6abc:8080/resource").build().encode();
215215
}
216216

217-
@Test // SPR-10539
218-
public void fromUriStringIPv6Host() throws URISyntaxException {
217+
@Test // SPR-10539
218+
public void fromUriStringIPv6Host() {
219219
UriComponents result = UriComponentsBuilder
220220
.fromUriString("http://[1abc:2abc:3abc::5ABC:6abc]:8080/resource").build().encode();
221221
assertEquals("[1abc:2abc:3abc::5ABC:6abc]", result.getHost());
@@ -229,7 +229,7 @@ public void fromUriStringIPv6Host() throws URISyntaxException {
229229
assertEquals("[::192.168.1.1]", resultIPv4compatible.getHost());
230230
}
231231

232-
@Test // SPR-11970
232+
@Test // SPR-11970
233233
public void fromUriStringNoPathWithReservedCharInQuery() {
234234
UriComponents result = UriComponentsBuilder.fromUriString("http://example.com?foo=bar@baz").build();
235235
assertTrue(StringUtils.isEmpty(result.getUserInfo()));
@@ -239,7 +239,7 @@ public void fromUriStringNoPathWithReservedCharInQuery() {
239239
}
240240

241241
@Test
242-
public void fromHttpRequest() throws URISyntaxException {
242+
public void fromHttpRequest() {
243243
MockHttpServletRequest request = new MockHttpServletRequest();
244244
request.setScheme("http");
245245
request.setServerName("localhost");
@@ -255,7 +255,7 @@ public void fromHttpRequest() throws URISyntaxException {
255255
assertEquals("a=1", result.getQuery());
256256
}
257257

258-
@Test // SPR-12771
258+
@Test // SPR-12771
259259
public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception {
260260
MockHttpServletRequest request = new MockHttpServletRequest();
261261
request.addHeader("X-Forwarded-Proto", "https");
@@ -275,7 +275,7 @@ public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception {
275275
assertEquals("/rest/mobile/users/1", result.getPath());
276276
}
277277

278-
@Test //SPR-14761
278+
@Test // SPR-14761
279279
public void fromHttpRequestWithForwardedIPv4Host() {
280280
MockHttpServletRequest request = new MockHttpServletRequest();
281281
request.setScheme("http");
@@ -290,7 +290,7 @@ public void fromHttpRequestWithForwardedIPv4Host() {
290290
assertEquals("http://192.168.0.1/mvc-showcase", result.toString());
291291
}
292292

293-
@Test //SPR-14761
293+
@Test // SPR-14761
294294
public void fromHttpRequestWithForwardedIPv6() {
295295
MockHttpServletRequest request = new MockHttpServletRequest();
296296
request.setScheme("http");
@@ -305,7 +305,7 @@ public void fromHttpRequestWithForwardedIPv6() {
305305
assertEquals("http://[1abc:2abc:3abc::5ABC:6abc]/mvc-showcase", result.toString());
306306
}
307307

308-
@Test //SPR-14761
308+
@Test // SPR-14761
309309
public void fromHttpRequestWithForwardedIPv6Host() {
310310
MockHttpServletRequest request = new MockHttpServletRequest();
311311
request.setScheme("http");
@@ -320,7 +320,7 @@ public void fromHttpRequestWithForwardedIPv6Host() {
320320
assertEquals("http://[1abc:2abc:3abc::5ABC:6abc]/mvc-showcase", result.toString());
321321
}
322322

323-
@Test //SPR-14761
323+
@Test // SPR-14761
324324
public void fromHttpRequestWithForwardedIPv6HostAndPort() {
325325
MockHttpServletRequest request = new MockHttpServletRequest();
326326
request.setScheme("http");
@@ -335,7 +335,6 @@ public void fromHttpRequestWithForwardedIPv6HostAndPort() {
335335
assertEquals("http://[1abc:2abc:3abc::5ABC:6abc]:8080/mvc-showcase", result.toString());
336336
}
337337

338-
339338
@Test
340339
public void fromHttpRequestWithForwardedHost() {
341340
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -351,7 +350,7 @@ public void fromHttpRequestWithForwardedHost() {
351350
assertEquals("http://anotherHost/mvc-showcase", result.toString());
352351
}
353352

354-
@Test // SPR-10701
353+
@Test // SPR-10701
355354
public void fromHttpRequestWithForwardedHostIncludingPort() {
356355
MockHttpServletRequest request = new MockHttpServletRequest();
357356
request.setScheme("http");
@@ -367,7 +366,7 @@ public void fromHttpRequestWithForwardedHostIncludingPort() {
367366
assertEquals(443, result.getPort());
368367
}
369368

370-
@Test // SPR-11140
369+
@Test // SPR-11140
371370
public void fromHttpRequestWithForwardedHostMultiValuedHeader() {
372371
MockHttpServletRequest request = new MockHttpServletRequest();
373372
request.setScheme("http");
@@ -382,7 +381,7 @@ public void fromHttpRequestWithForwardedHostMultiValuedHeader() {
382381
assertEquals(-1, result.getPort());
383382
}
384383

385-
@Test // SPR-11855
384+
@Test // SPR-11855
386385
public void fromHttpRequestWithForwardedHostAndPort() {
387386
MockHttpServletRequest request = new MockHttpServletRequest();
388387
request.setScheme("http");
@@ -398,7 +397,7 @@ public void fromHttpRequestWithForwardedHostAndPort() {
398397
assertEquals(9090, result.getPort());
399398
}
400399

401-
@Test // SPR-11872
400+
@Test // SPR-11872
402401
public void fromHttpRequestWithForwardedHostWithDefaultPort() {
403402
MockHttpServletRequest request = new MockHttpServletRequest();
404403
request.setScheme("http");
@@ -413,7 +412,7 @@ public void fromHttpRequestWithForwardedHostWithDefaultPort() {
413412
assertEquals(-1, result.getPort());
414413
}
415414

416-
@Test // SPR-16262
415+
@Test // SPR-16262
417416
public void fromHttpRequestWithForwardedProtoWithDefaultPort() {
418417
MockHttpServletRequest request = new MockHttpServletRequest();
419418
request.setScheme("http");
@@ -447,7 +446,7 @@ public void fromHttpRequestWithForwardedHostWithForwardedScheme() {
447446
assertEquals(-1, result.getPort());
448447
}
449448

450-
@Test // SPR-12771
449+
@Test // SPR-12771
451450
public void fromHttpRequestWithForwardedProtoAndDefaultPort() {
452451
MockHttpServletRequest request = new MockHttpServletRequest();
453452
request.setScheme("http");
@@ -464,7 +463,7 @@ public void fromHttpRequestWithForwardedProtoAndDefaultPort() {
464463
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
465464
}
466465

467-
@Test // SPR-12813
466+
@Test // SPR-12813
468467
public void fromHttpRequestWithForwardedPortMultiValueHeader() {
469468
MockHttpServletRequest request = new MockHttpServletRequest();
470469
request.setScheme("http");
@@ -480,7 +479,7 @@ public void fromHttpRequestWithForwardedPortMultiValueHeader() {
480479
assertEquals("http://a.example.org/mvc-showcase", result.toString());
481480
}
482481

483-
@Test // SPR-12816
482+
@Test // SPR-12816
484483
public void fromHttpRequestWithForwardedProtoMultiValueHeader() {
485484
MockHttpServletRequest request = new MockHttpServletRequest();
486485
request.setScheme("http");
@@ -497,7 +496,7 @@ public void fromHttpRequestWithForwardedProtoMultiValueHeader() {
497496
assertEquals("https://a.example.org/mvc-showcase", result.toString());
498497
}
499498

500-
@Test // SPR-12742
499+
@Test // SPR-12742
501500
public void fromHttpRequestWithTrailingSlash() throws Exception {
502501
UriComponents before = UriComponentsBuilder.fromPath("/foo/").build();
503502
UriComponents after = UriComponentsBuilder.newInstance().uriComponents(before).build();
@@ -567,7 +566,7 @@ public void pathSegmentsSomeEmpty() {
567566
assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments());
568567
}
569568

570-
@Test // SPR-12398
569+
@Test // SPR-12398
571570
public void pathWithDuplicateSlashes() throws URISyntaxException {
572571
UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo/////////bar").build();
573572
assertEquals("/foo/bar", uriComponents.getPath());
@@ -761,7 +760,7 @@ public void testClone() throws URISyntaxException {
761760
assertEquals("f2", result2.getFragment());
762761
}
763762

764-
@Test // SPR-11856
763+
@Test // SPR-11856
765764
public void fromHttpRequestForwardedHeader() throws Exception {
766765
MockHttpServletRequest request = new MockHttpServletRequest();
767766
request.addHeader("Forwarded", "proto=https; host=84.198.58.199");
@@ -900,4 +899,14 @@ public void fromHttpRequestForwardedHeaderWithProtoAndServerPort() throws Except
900899
assertEquals(-1, result.getPort());
901900
assertEquals("https://example.com/rest/mobile/users/1", result.toUriString());
902901
}
902+
903+
@Test // SPR-16364
904+
public void uriComponentsNotEqualAfterNormalization() {
905+
UriComponents uri1 = UriComponentsBuilder.fromUriString("http://test.com").build().normalize();
906+
UriComponents uri2 = UriComponentsBuilder.fromUriString("http://test.com/").build();
907+
assertTrue(uri1.getPathSegments().isEmpty());
908+
assertTrue(uri2.getPathSegments().isEmpty());
909+
assertNotEquals(uri1, uri2);
910+
}
911+
903912
}

0 commit comments

Comments
 (0)