Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit eace1cb

Browse files
committed
fixup! fix($browser): normalize all optionally en/decoded characters when comparing URLs
1 parent c8b94c8 commit eace1cb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/ng/urlUtils.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// https://tools.ietf.org/html/rfc3986#appendix-A
55
var sub_delims = '!$&\'()*+,;=';
66
var alpha = 'abcdefghijklmnopqrstuvwxyz';
7-
var digit = '0123456789'
7+
var digit = '0123456789';
88
var unreserved = alpha + digit + '-._~';
9-
var pchar = unreserved + sub_delims + ':' + '@'; //pct-encoded excluded
10-
var query = (pchar + '/' + '?').replace(/[&=]/g, ''); //&= excluded
11-
var fragment = pchar + '/' + '?';
9+
var pchar = unreserved + sub_delims + ':@'; //pct-encoded excluded
10+
var query = (pchar + '/?').replace(/[&=]/g, ''); //&= excluded
11+
var fragment = pchar + '/?';
1212

1313
// Map of the encoded version of all characters not requiring encoding
1414
var PATH_NON_ENCODED = charsToEncodedMap(pchar);
@@ -126,9 +126,15 @@ function urlResolve(url) {
126126
// No browser normalizes all of the optionally encoded characters consistently.
127127
// Various browsers normalize a subsets of the unreserved characters within the
128128
// path, search and hash portions of the URL.
129-
urlParsingNode.pathname = normalizeUriPath(urlParsingNode.pathname);
130-
urlParsingNode.search = normalizeUriQuery(urlParsingNode.search.replace(/^\?/, ''));
131-
urlParsingNode.hash = normalizeUriFragment(urlParsingNode.hash.replace(/^\#/, ''));
129+
if (urlParsingNode.pathname) {
130+
urlParsingNode.pathname = normalizeUriPath(urlParsingNode.pathname);
131+
}
132+
if (urlParsingNode.search) {
133+
urlParsingNode.search = normalizeUriQuery(urlParsingNode.search.replace(/^\?/, ''));
134+
}
135+
if (urlParsingNode.hash) {
136+
urlParsingNode.hash = normalizeUriFragment(urlParsingNode.hash.replace(/^#/, ''));
137+
}
132138

133139
return {
134140
href: urlParsingNode.href,

0 commit comments

Comments
 (0)