Skip to content

Commit

Permalink
Fix authority parsing in Closure URI parser.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 288978923
  • Loading branch information
12wrigja authored and kjin committed Jan 10, 2020
1 parent bf42e87 commit ac0736b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion closure/goog/uri/utils.js
Expand Up @@ -195,7 +195,7 @@ goog.uri.utils.splitRe_ = new RegExp(
'(?:([^/?#]*)@)?' + // userInfo
'([^/#?]*?)' + // domain
'(?::([0-9]+))?' + // port
'(?=[/#?]|$)' + // authority-terminating character
'(?=[/\\\\#?]|$)' + // authority-terminating character
')?' +
'([^?#]+)?' + // path
'(?:\\?([^#]*))?' + // query
Expand Down
13 changes: 13 additions & 0 deletions closure/goog/uri/utils_test.js
Expand Up @@ -106,6 +106,19 @@ testSuite({
assertEquals('fragment', utils.getFragment(uri));
},

testSplitMaliciousUri() {
const uri = 'https://malicious.com\\test.google.com';
assertEquals('https', utils.getScheme(uri));
assertEquals('malicious.com', utils.getDomain(uri));
assertEquals('malicious.com', utils.getDomainEncoded(uri));
assertNull(utils.getPort(uri));
assertEquals('\\test.google.com', utils.getPathEncoded(uri));
assertEquals('\\test.google.com', utils.getPath(uri));
assertNull(utils.getQueryData(uri));
assertNull(utils.getFragmentEncoded(uri));
assertNull(utils.getFragment(uri));
},

testSplitBadAuthority() {
// This URL has a syntax error per the RFC (port number must be digits, and
// host cannot contain a colon except in [...]). This test is solely to
Expand Down

0 comments on commit ac0736b

Please sign in to comment.