Skip to content

Commit

Permalink
Fix validation of redirect rules with empty resource
Browse files Browse the repository at this point in the history
The `empty` resource is a special case, it does not
require a network type to be present to be valid.
  • Loading branch information
gorhill committed Jun 15, 2020
1 parent cb5437b commit f8b0ee0
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ const Parser = class {
return true;
}

hasFlavor(bits) {
return hasBits(this.flavorBits, bits);
}

isException() {
return hasBits(this.flavorBits, BITFlavorException);
}
Expand Down Expand Up @@ -2108,8 +2112,19 @@ const NetOptionsIterator = class {
);
}
}
// `redirect` requires one single network type
if ( redirectIndex !== -1 && typeCount !== 1 && networkTypeCount !== 1 ) {
// `redirect` requires one single network type, EXCEPT for when we
// redirect to `empty`, in which case it is allowed to not have any
// network type specified.
if (
( redirectIndex !== -1 ) &&
( typeCount !== 1 || networkTypeCount !== 1 ) &&
( typeCount !== 0 || networkTypeCount !== 0 ||
this.parser.raw.slice(
this.parser.slices[optSlices[redirectIndex+4]+1],
this.parser.slices[optSlices[redirectIndex+5]+1]
) !== 'empty'
)
) {
optSlices[redirectIndex] = OPTTokenInvalid;
if ( this.interactive ) {
this.parser.markSlices(
Expand Down

0 comments on commit f8b0ee0

Please sign in to comment.