You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
url: use SafeSet to filter known special protocols
Avoids a maintenance hazard when reviewers assume that
`hostlessProtocol` and `slashedProtocol` are disjoint.
The following may be counter-intuitive:
```js
// These objects seem to have no keys in common
const hostlessProtocol = { 'javascript': true };
const slashedProtocol = { 'http': true };
// A reasonable reviewer may assumes bothTrue is never truthy
function bothTrue(lowerProto) {
return hostlessProtocol[lowerProto] && slashedProtocol[lowerProto];
}
// But
console.log(Boolean(bothTrue('constructor'))); // true
```
This change uses SafeSet instead of plain-old objects.
----
Rejected alternative:
We could have used object with a `null` prototype as lookup tables
so that `lowerProto` is never treated as a key into `Object.prototype`.
```js
const hostlessProtocol = { __proto__: null, 'javascript': true };
const slashedProtocol = { __proto__: null, 'http': true };
function bothTrue(lowerProto) {
return hostlessProtocol[lowerProto] && slashedProtocol[lowerProto];
}
console.log(Boolean(bothTrue('constructor'))); // false
```
PR-URL: #24703
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@@ -701,7 +703,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
701
703
}
702
704
703
705
// urlParse appends trailing / to urls like http://www.example.com
704
-
if(slashedProtocol[result.protocol]&&
706
+
if(slashedProtocol.has(result.protocol)&&
705
707
result.hostname&&!result.pathname){
706
708
result.path=result.pathname='/';
707
709
}
@@ -719,7 +721,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
719
721
// if it is file:, then the host is dropped,
720
722
// because that's known to be hostless.
721
723
// anything else is assumed to be absolute.
722
-
if(!slashedProtocol[relative.protocol]){
724
+
if(!slashedProtocol.has(relative.protocol)){
723
725
varkeys=Object.keys(relative);
724
726
for(varv=0;v<keys.length;v++){
725
727
vark=keys[v];
@@ -732,7 +734,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
0 commit comments