Skip to content

Commit

Permalink
Refine handling of illegal characters in userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sideshowbarker committed Dec 17, 2018
1 parent 1e647f6 commit 6696412
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/mola/galimatias/URLParser.java
Expand Up @@ -532,6 +532,7 @@ else if (c == '#') {

for (int i = 0; i < buffer.codePointCount(0, buffer.length()); i++) {
final int otherChar = buffer.codePointAt(i);
final char startChar = buffer.charAt(i);
if (
otherChar == 0x0009 ||
otherChar == 0x000A ||
Expand All @@ -540,8 +541,8 @@ else if (c == '#') {
handleIllegalWhitespaceError();
continue;
}
if (!isURLCodePoint(otherChar) && otherChar != '%') {
handleIllegalCharacterError("Illegal character in user or password", buffer.codePointAt(i));
if (!isURLCodePoint(startChar) && startChar != '%') {
handleIllegalCharacterError("Illegal character in user or password", otherChar);
}
if (otherChar == '%') {
if (i + 2 >= buffer.length() || !isASCIIHexDigit(buffer.charAt(i+1)) || !isASCIIHexDigit(buffer.charAt(i+2))) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/io/mola/galimatias/ParseIssueTest.java
Expand Up @@ -42,6 +42,7 @@ public static Collection<Object[]> data() {
{ "http://www.example.com/%", ParseIssue.INVALID_PERCENT_ENCODING, false },
{ "http://www.example.com\\path", ParseIssue.BACKSLASH_AS_DELIMITER, false },
{ "http://us`er:pass@www.example.com/path", ParseIssue.ILLEGAL_CHARACTER, false },
{ "http://:\uD83D\uDCA9@example.com/bar", ParseIssue.ILLEGAL_CHARACTER, false },
{ "http://www.exam\tple.com/path", ParseIssue.ILLEGAL_WHITESPACE, false },
{ "http://user:pass@/path", ParseIssue.INVALID_HOST, true }
});
Expand Down

0 comments on commit 6696412

Please sign in to comment.