Created
August 20, 2019 02:55
-
-
Save gregw/6b5f9ff6f05bf6ed49287d609d1c189e to your computer and use it in GitHub Desktop.
URIUtil normalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java | |
index b86a1b7958..4c22f8536c 100644 | |
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java | |
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/URIUtil.java | |
@@ -22,6 +22,7 @@ import java.net.URI; | |
import java.net.URISyntaxException; | |
import java.nio.charset.Charset; | |
import java.nio.charset.StandardCharsets; | |
+import java.text.Normalizer; | |
import org.eclipse.jetty.util.Utf8Appendable.NotUtf8Exception; | |
import org.eclipse.jetty.util.log.Log; | |
@@ -457,6 +458,7 @@ public class URIUtil | |
{ | |
try | |
{ | |
+ boolean normalize = false; | |
Utf8StringBuilder builder = null; | |
int end = offset + length; | |
for (int i = offset; i < end; i++) | |
@@ -465,6 +467,7 @@ public class URIUtil | |
switch (c) | |
{ | |
case '%': | |
+ normalize = true; | |
if (builder == null) | |
{ | |
builder = new Utf8StringBuilder(path.length()); | |
@@ -511,17 +514,23 @@ public class URIUtil | |
break; | |
default: | |
+ normalize |= (c < 0 || c > 0x7f); | |
if (builder != null) | |
builder.append(c); | |
break; | |
} | |
} | |
+ String result; | |
if (builder != null) | |
- return builder.toString(); | |
- if (offset == 0 && length == path.length()) | |
- return path; | |
- return path.substring(offset, end); | |
+ result = builder.toString(); | |
+ else if (offset == 0 && length == path.length()) | |
+ result = path; | |
+ else | |
+ result = path.substring(offset, end); | |
+ if (normalize) | |
+ result = Normalizer.normalize(result, Normalizer.Form.NFC); | |
+ return result; | |
} | |
catch (NotUtf8Exception e) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment