UriUtils.extractFileExtension properly handles all fragments
Issue: SPR-15786
This commit is contained in:
parent
ac1d3b22c9
commit
13080f04f4
|
@ -336,11 +336,12 @@ public abstract class UriUtils {
|
|||
@Nullable
|
||||
public static String extractFileExtension(String path) {
|
||||
int end = path.indexOf('?');
|
||||
int fragmentIndex = path.indexOf('#');
|
||||
if (fragmentIndex != -1 && (end == -1 || fragmentIndex < end)) {
|
||||
end = fragmentIndex;
|
||||
}
|
||||
if (end == -1) {
|
||||
end = path.indexOf('#');
|
||||
if (end == -1) {
|
||||
end = path.length();
|
||||
}
|
||||
end = path.length();
|
||||
}
|
||||
int begin = path.lastIndexOf('/', end) + 1;
|
||||
int paramIndex = path.indexOf(';', begin);
|
||||
|
|
|
@ -27,6 +27,7 @@ import static org.junit.Assert.*;
|
|||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @author Med Belamachi
|
||||
*/
|
||||
public class UriUtilsTests {
|
||||
|
||||
|
@ -115,6 +116,8 @@ public class UriUtilsTests {
|
|||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/a"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/path/a"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/path/a.do"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html#aaa?bbb"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html#aaa.xml?bbb"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=a"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a"));
|
||||
assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a.do"));
|
||||
|
|
Loading…
Reference in New Issue