Skip to content

Commit f6108cf

Browse files
authored
fix: fix Edge browser regex, minor version is required (#1533)
fixes #1530
1 parent 6f48342 commit f6108cf

4 files changed

Lines changed: 98 additions & 60 deletions

File tree

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,40 @@
6767
},
6868
"dependencies": {
6969
"argue-cli": "^2.1.0",
70-
"easy-table": "^1.1.1",
70+
"easy-table": "^1.2.0",
7171
"picocolors": "^1.0.0",
7272
"regexp-tree": "^0.1.24",
73-
"ua-regexes-lite": "^1.1.3"
73+
"ua-regexes-lite": "^1.2.1"
7474
},
7575
"devDependencies": {
76-
"@commitlint/cli": "^18.0.0",
77-
"@commitlint/config-conventional": "^18.0.0",
78-
"@commitlint/cz-commitlint": "^18.0.0",
76+
"@commitlint/cli": "^18.4.3",
77+
"@commitlint/config-conventional": "^18.4.3",
78+
"@commitlint/cz-commitlint": "^18.4.3",
7979
"@rollup/plugin-node-resolve": "^15.0.1",
8080
"@size-limit/file": "^11.0.0",
8181
"@swc/core": "^1.3.20",
82-
"@swc/helpers": "^0.5.0",
82+
"@swc/helpers": "^0.5.1",
8383
"@trigen/browserslist-config": "8.0.0-alpha.27",
8484
"@trigen/eslint-config": "8.0.0-alpha.29",
8585
"@trigen/scripts": "8.0.0-alpha.29",
86-
"@types/node": "^20.0.0",
87-
"@vitest/coverage-v8": "^0.34.0",
88-
"browserslist": "^4.21.4",
86+
"@types/node": "^20.10.1",
87+
"@vitest/coverage-v8": "^0.34.4",
88+
"browserslist": "^4.22.2",
8989
"clean-publish": "^4.0.1",
9090
"commitizen": "^4.2.5",
9191
"del-cli": "^5.0.0",
9292
"eslint": "^8.28.0",
9393
"nano-staged": "^0.8.0",
94-
"rollup": "^4.0.0",
95-
"rollup-plugin-add-shebang": "^0.3.0",
96-
"rollup-plugin-swc3": "^0.10.0",
94+
"rollup": "^4.6.1",
95+
"rollup-plugin-add-shebang": "^0.3.1",
96+
"rollup-plugin-swc3": "^0.10.1",
9797
"simple-git-hooks": "^2.8.1",
9898
"simple-github-release": "^1.0.0",
9999
"size-limit": "^11.0.0",
100100
"standard-version": "^9.5.0",
101-
"typedoc": "^0.25.0",
102-
"typescript": "^5.0.0",
103-
"vite": "^5.0.0",
104-
"vitest": "^0.34.0"
101+
"typedoc": "^0.25.1",
102+
"typescript": "^5.1.3",
103+
"vite": "^5.0.4",
104+
"vitest": "^0.34.4"
105105
}
106106
}

pnpm-lock.yaml

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/useragentRegex/useragentRegex.spec.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import {
77

88
function* getUserAgents() {
99
const regexesCache = new Map<string, RegExp>()
10-
const getRegex = (query: string) => {
11-
let regex = regexesCache.get(query)
10+
const getRegex = (query: string, allowHigherVersions = true) => {
11+
const key = `${query}:${allowHigherVersions}`
12+
let regex = regexesCache.get(key)
1213

1314
if (!regex) {
1415
regex = getUserAgentRegex({
1516
browsers: query,
16-
allowHigherVersions: true,
17+
allowHigherVersions,
1718
allowZeroSubversions: true
1819
})
19-
regexesCache.set(query, regex)
20+
regexesCache.set(key, regex)
2021
}
2122

2223
return regex
@@ -27,8 +28,9 @@ function* getUserAgents() {
2728
for (const query of useragent.yes) {
2829
yield {
2930
ua: useragent.ua,
30-
regex: getRegex(query),
31+
regex: getRegex(query, useragent.allowHigherVersions),
3132
query,
33+
allowHigherVersions: useragent.allowHigherVersions,
3234
should: true
3335
}
3436
}
@@ -38,7 +40,8 @@ function* getUserAgents() {
3840
for (const query of useragent.no) {
3941
yield {
4042
ua: useragent.ua,
41-
regex: getRegex(query),
43+
regex: getRegex(query, useragent.allowHigherVersions),
44+
allowHigherVersions: useragent.allowHigherVersions,
4245
query,
4346
should: false
4447
}
@@ -47,10 +50,18 @@ function* getUserAgents() {
4750
}
4851
}
4952

50-
function inspect(query: string, ua: string, should: boolean) {
53+
interface UserAgentTest {
54+
ua: string
55+
regex: RegExp
56+
query: string
57+
allowHigherVersions?: boolean
58+
should: boolean
59+
}
60+
61+
function inspect({ query, ua, should, allowHigherVersions }: UserAgentTest) {
5162
const info = getUserAgentRegexes({
5263
browsers: query,
53-
allowHigherVersions: true,
64+
allowHigherVersions,
5465
allowZeroSubversions: true
5566
})
5667
const message = `${should ? 'Should' : 'Should not'} matches:
@@ -74,7 +85,7 @@ describe('UserAgentRegex', () => {
7485
res = ua.regex.test(ua.ua)
7586

7687
if (res !== ua.should) {
77-
inspect(ua.query, ua.ua, ua.should)
88+
inspect(ua)
7889
}
7990
}
8091
})

test/useragents.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,47 @@ export const useragents = [
9797
ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.25',
9898
yes: ['edge 105', 'edge >= 105', 'chrome 105']
9999
},
100+
/**
101+
* Edge bug #1530
102+
*/
103+
{
104+
ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36 Edge/120.0',
105+
allowHigherVersions: false,
106+
yes: ['edge 120'],
107+
no: ['edge 12']
108+
},
100109
/**
101110
* Firefox Desktop
102111
*/
103112
{
104113
ua: 'Mozilla/5.0 (Windows NT 5.2; rv:42.0) Gecko/20100101 Firefox/42.0',
105114
yes: ['firefox >= 40']
106115
},
116+
/**
117+
* Firefox Desktop bug #1530
118+
*/
119+
{
120+
ua: 'Mozilla/5.0 (Windows NT 5.2; rv:42.0) Gecko/20100101 Firefox/120.0',
121+
allowHigherVersions: false,
122+
yes: ['firefox 120'],
123+
no: ['firefox 12']
124+
},
107125
/**
108126
* Chrome Desktop
109127
*/
110128
{
111129
ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36',
112130
yes: ['chrome >= 60']
113131
},
132+
/**
133+
* Chrome Desktop bug #1530
134+
*/
135+
{
136+
ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36',
137+
allowHigherVersions: false,
138+
yes: ['chrome 120'],
139+
no: ['chrome 12']
140+
},
114141
/**
115142
* Safari Desktop
116143
*/

0 commit comments

Comments
 (0)