Skip to content

Commit 93ce67a

Browse files
committed
🐛 处理tld域名
1 parent c0da6a0 commit 93ce67a

5 files changed

Lines changed: 19 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scriptcat",
3-
"version": "0.18.0-beta",
3+
"version": "0.18.1-beta",
44
"description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!",
55
"author": "CodFrm",
66
"license": "GPLv3",

src/app/service/service_worker/gm_api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,6 @@ export default class GMApi {
11571157
removeRuleIds: [parseInt(requestId)],
11581158
addRules: [rule],
11591159
});
1160-
console.log("old rule", requestId, rule);
11611160
return;
11621161
}
11631162
this.gmXhrHeadersReceived.emit("headersReceived:" + requestId, details);

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "__MSG_scriptcat__",
4-
"version": "0.18.0.1100",
4+
"version": "0.18.1.1100",
55
"author": "CodFrm",
66
"description": "__MSG_scriptcat_description__",
77
"options_ui": {

src/pkg/utils/match.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,17 @@ describe("dealPatternMatches", () => {
157157
"*.example.com/path/*",
158158
"http*",
159159
"/^.*?://.*?.example.com.*?$/",
160+
"*://*.example.tld/*",
160161
]);
161162
expect(matches.patternResult).toEqual([
162163
"*://*/*",
163164
"*://*.example.com/*",
164165
"*://*.example.com/*",
165166
"*://example.com/*",
166167
"*://*.example.com/path/*",
167-
"*://*/*",
168-
"*://*/*",
168+
"*://*/*", // http*
169+
"*://*/*", // 正则
170+
"*://*/*", // tld
169171
]);
170172
expect(matches.result).toEqual([
171173
"*://www.example.com*",
@@ -175,6 +177,7 @@ describe("dealPatternMatches", () => {
175177
"*.example.com/path/*",
176178
"http*",
177179
"/^.*?://.*?.example.com.*?$/",
180+
"*://*.example.tld/*",
178181
]);
179182
});
180183
it("特殊情况-exclude", () => {
@@ -246,6 +249,14 @@ describe("parsePatternMatchesURL", () => {
246249
path: "search",
247250
});
248251
});
252+
it("tld顶级域名", () => {
253+
const matches = parsePatternMatchesURL("http://*.example.tld/*");
254+
expect(matches).toEqual({
255+
scheme: "http",
256+
host: "*",
257+
path: "*",
258+
});
259+
});
249260
it("一些怪异的情况", () => {
250261
let matches = parsePatternMatchesURL("*://*./*");
251262
expect(matches).toEqual({

src/pkg/utils/match.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ export function parsePatternMatchesURL(
333333
if (pos !== undefined && pos !== -1) {
334334
result!.host = `${result!.host.substring(0, pos)}:*`;
335335
}
336+
// 如果host以.tld结尾
337+
if (result?.host.endsWith(".tld")) {
338+
result.host = "*";
339+
}
336340
return result;
337341
}
338342

0 commit comments

Comments
 (0)