Skip to content

Commit 0369751

Browse files
authored
fix: faithfully match an empty set of browsers (#1583)
If the query matches no browsers, generate `/[]/` which matches nothing rather than `/(?:)/` which matches everything. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 528b121 commit 0369751

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/regex/nodes.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,15 @@ export function RepetitionNode(expression: Expression, quantifier: Quantifier):
109109
}
110110
}
111111

112-
export function DisjunctionNode(...expressions: (Expression | Expression[])[]): Disjunction | Expression {
112+
export function DisjunctionNode(...expressions: (Expression | Expression[])[]): Disjunction | Expression | CharacterClass {
113113
const exprs = concat(expressions).filter(Boolean)
114114

115-
if (exprs.length === 1) {
115+
if (exprs.length === 0) {
116+
return {
117+
type: 'CharacterClass',
118+
expressions: []
119+
}
120+
} else if (exprs.length === 1) {
116121
return exprs[0]
117122
}
118123

test/useragents.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ export const useragents = [
111111
*/
112112
{
113113
ua: 'Mozilla/5.0 (Windows NT 5.2; rv:42.0) Gecko/20100101 Firefox/42.0',
114-
yes: ['firefox >= 40']
114+
yes: ['firefox >= 40'],
115+
no: ['> 9000%']
115116
},
116117
/**
117118
* Firefox Desktop bug #1530

0 commit comments

Comments
 (0)