Skip to content

Commit 6d8bf34

Browse files
committed
Suppress decoding error for resource path
Closes gh-23463
1 parent b86c11c commit 6d8bf34

File tree

8 files changed

+36
-14
lines changed

8 files changed

+36
-14
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/resource/PathResourceResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ private boolean isInvalidEncodedPath(String resourcePath) {
203203
return true;
204204
}
205205
}
206+
catch (IllegalArgumentException ex) {
207+
// May not be possible to decode...
208+
}
206209
catch (UnsupportedEncodingException ex) {
207210
// Should never happen...
208211
}

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -468,7 +468,10 @@ private boolean isInvalidEncodedPath(String path) {
468468
return true;
469469
}
470470
}
471-
catch (IllegalArgumentException | UnsupportedEncodingException ex) {
471+
catch (IllegalArgumentException ex) {
472+
// May not be possible to decode...
473+
}
474+
catch (UnsupportedEncodingException ex) {
472475
// Should never happen...
473476
}
474477
}

spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ private void testCheckResource(Resource location, String requestPath) throws IOE
109109
assertNull(actual);
110110
}
111111

112+
@Test // gh-23463
113+
public void ignoreInvalidEscapeSequence() throws IOException {
114+
UrlResource location = new UrlResource(getClass().getResource("./test/"));
115+
Resource resource = location.createRelative("test%file.txt");
116+
assertTrue(this.resolver.checkResource(resource, location));
117+
}
118+
112119
@Test
113120
public void checkResourceWithAllowedLocations() {
114121
this.resolver.setAllowedLocations(

spring-webflux/src/test/resources/org/springframework/web/reactive/resource/test/test%file.txt

Whitespace-only changes.

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -288,6 +288,9 @@ private boolean isInvalidEncodedPath(String resourcePath) {
288288
return true;
289289
}
290290
}
291+
catch (IllegalArgumentException ex) {
292+
// May not be possible to decode...
293+
}
291294
catch (UnsupportedEncodingException ex) {
292295
// Should never happen...
293296
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -605,7 +605,10 @@ private boolean isInvalidEncodedPath(String path) {
605605
return true;
606606
}
607607
}
608-
catch (IllegalArgumentException | UnsupportedEncodingException ex) {
608+
catch (IllegalArgumentException ex) {
609+
// May not be possible to decode...
610+
}
611+
catch (UnsupportedEncodingException ex) {
609612
// Should never happen...
610613
}
611614
}

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -90,6 +90,13 @@ private void testCheckResource(Resource location, String requestPath) throws IOE
9090
assertNull(actual);
9191
}
9292

93+
@Test // gh-23463
94+
public void ignoreInvalidEscapeSequence() throws IOException {
95+
UrlResource location = new UrlResource(getClass().getResource("./test/"));
96+
Resource resource = location.createRelative("test%file.txt");
97+
assertTrue(this.resolver.checkResource(resource, location));
98+
}
99+
93100
@Test
94101
public void checkResourceWithAllowedLocations() {
95102
this.resolver.setAllowedLocations(
@@ -103,8 +110,7 @@ public void checkResourceWithAllowedLocations() {
103110
assertEquals("../testalternatepath/bar.css", actual);
104111
}
105112

106-
// SPR-12432
107-
@Test
113+
@Test // SPR-12432
108114
public void checkServletContextResource() throws Exception {
109115
Resource classpathLocation = new ClassPathResource("test/", PathResourceResolver.class);
110116
MockServletContext context = new MockServletContext();
@@ -116,24 +122,21 @@ public void checkServletContextResource() throws Exception {
116122
assertTrue(this.resolver.checkResource(resource, servletContextLocation));
117123
}
118124

119-
// SPR-12624
120-
@Test
125+
@Test // SPR-12624
121126
public void checkRelativeLocation() throws Exception {
122127
String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
123128
Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
124129

125130
assertNotNull(this.resolver.resolveResource(null, "main.css", Collections.singletonList(location), null));
126131
}
127132

128-
// SPR-12747
129-
@Test
133+
@Test // SPR-12747
130134
public void checkFileLocation() throws Exception {
131135
Resource resource = getResource("main.css");
132136
assertTrue(this.resolver.checkResource(resource, resource));
133137
}
134138

135-
// SPR-13241
136-
@Test
139+
@Test // SPR-13241
137140
public void resolvePathRootResource() {
138141
Resource webjarsLocation = new ClassPathResource("/META-INF/resources/webjars/", PathResourceResolver.class);
139142
String path = this.resolver.resolveUrlPathInternal("", Collections.singletonList(webjarsLocation), null);

spring-webmvc/src/test/resources/org/springframework/web/servlet/resource/test/test%file.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)