Skip to content

Commit 74fb264

Browse files
committed
Fix LookupPath parsing
Issue: SPR-15397
1 parent 4d52590 commit 74fb264

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

spring-web/src/main/java/org/springframework/web/server/support/LookupPath.java

+11-25
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.server.support;
1818

1919
import org.springframework.lang.Nullable;
20-
import org.springframework.web.server.ServerWebExchange;
2120

2221
/**
2322
* Lookup path information of an incoming HTTP request.
@@ -32,30 +31,23 @@ public final class LookupPath {
3231

3332
private final String path;
3433

35-
private final int fileExtensionIndex;
34+
private final int fileExtStartIndex;
3635

37-
private final int pathParametersIndex;
36+
private final int fileExtEndIndex;
3837

39-
public LookupPath(String path, int fileExtensionIndex, int pathParametersIndex) {
38+
public LookupPath(String path, int fileExtStartIndex, int fileExtEndIndex) {
4039
this.path = path;
41-
this.fileExtensionIndex = fileExtensionIndex;
42-
this.pathParametersIndex = pathParametersIndex;
40+
this.fileExtStartIndex = fileExtStartIndex;
41+
this.fileExtEndIndex = fileExtEndIndex;
4342
}
4443

4544
public String getPath() {
46-
if (this.pathParametersIndex != -1) {
47-
// TODO: variant without the path parameter information?
48-
//return this.path.substring(0, this.pathParametersIndex);
4945
return this.path;
50-
}
51-
else {
52-
return this.path;
53-
}
5446
}
5547

5648
public String getPathWithoutExtension() {
57-
if (this.fileExtensionIndex != -1) {
58-
return this.path.substring(0, this.fileExtensionIndex);
49+
if (this.fileExtStartIndex != -1) {
50+
return this.path.substring(0, this.fileExtStartIndex);
5951
}
6052
else {
6153
return this.path;
@@ -64,21 +56,15 @@ public String getPathWithoutExtension() {
6456

6557
@Nullable
6658
public String getFileExtension() {
67-
if (this.fileExtensionIndex == -1) {
59+
if (this.fileExtStartIndex == -1) {
6860
return null;
6961
}
70-
else if (this.pathParametersIndex == -1) {
71-
return this.path.substring(this.fileExtensionIndex);
62+
else if (this.fileExtEndIndex == -1) {
63+
return this.path.substring(this.fileExtStartIndex);
7264
}
7365
else {
74-
return this.path.substring(this.fileExtensionIndex, this.pathParametersIndex);
66+
return this.path.substring(this.fileExtStartIndex, this.fileExtEndIndex);
7567
}
7668
}
7769

78-
@Nullable
79-
public String getPathParameters() {
80-
return this.pathParametersIndex == -1 ?
81-
null : this.path.substring(this.pathParametersIndex + 1);
82-
}
83-
8470
}

spring-web/src/test/java/org/springframework/web/server/support/LookupPathTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ public void parsePathWithExtension() {
4646

4747
@Test
4848
public void parsePathWithParams() {
49-
LookupPath path = create("/test/foo.txt;foo=bar?framework=spring");
50-
assertEquals("/test/foo.txt;foo=bar", path.getPath());
51-
assertEquals("/test/foo", path.getPathWithoutExtension());
49+
LookupPath path = create("/test;spring=framework/foo.txt;foo=bar?framework=spring");
50+
assertEquals("/test;spring=framework/foo.txt;foo=bar", path.getPath());
51+
assertEquals("/test;spring=framework/foo", path.getPathWithoutExtension());
5252
assertEquals(".txt", path.getFileExtension());
53-
assertEquals("foo=bar", path.getPathParameters());
5453
}
5554

5655
private LookupPath create(String path) {

0 commit comments

Comments
 (0)