Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(parse): remove leading whitespace
reported by @P0cas via huntr.dev
  • Loading branch information
rodneyrehm committed Mar 3, 2022
1 parent efae1e5 commit 86d1052
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/URI.js
Expand Up @@ -239,6 +239,7 @@
// balanced parens inclusion (), [], {}, <>
parens: /(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g,
};
URI.leading_whitespace_expression = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/
// http://www.iana.org/assignments/uri-schemes.html
// http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports
URI.defaultPorts = {
Expand Down Expand Up @@ -494,6 +495,9 @@
preventInvalidHostname: URI.preventInvalidHostname
};
}

string = string.replace(URI.leading_whitespace_expression, '')

// [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]

// extract fragment
Expand Down
49 changes: 49 additions & 0 deletions test/urls.js
Expand Up @@ -2571,6 +2571,55 @@ var urls = [{
idn: false,
punycode: false
}
}, {
name: 'leading white space',
url: '\t\bhttp://www.example.org/?hello=world',
_url: 'http://www.example.org/?hello=world',
parts: {
protocol: 'http',
username: null,
password: null,
hostname: 'www.example.org',
port: null,
path: '/',
query: 'hello=world',
fragment: null
},
accessors: {
protocol: 'http',
username: '',
password: '',
port: '',
path: '/',
query: 'hello=world',
fragment: '',
resource: '/?hello=world',
authority: 'www.example.org',
origin: 'http://www.example.org',
userinfo: '',
subdomain: 'www',
domain: 'example.org',
tld: 'org',
directory: '/',
filename: '',
suffix: '',
hash: '',
search: '?hello=world',
host: 'www.example.org',
hostname: 'www.example.org'
},
is: {
urn: false,
url: true,
relative: false,
name: true,
sld: false,
ip: false,
ip4: false,
ip6: false,
idn: false,
punycode: false
}
}
];

1 comment on commit 86d1052

@P0cas
Copy link

@P0cas P0cas commented on 86d1052 Mar 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. Can you check the mail?

Please sign in to comment.