|
1 | | -// eslint-disable-next-line max-classes-per-file |
| 1 | +/* eslint-disable max-classes-per-file */ |
| 2 | + |
| 3 | +import Logger from "@App/app/logger/logger"; |
| 4 | + |
2 | 5 | export default class Match<T> { |
3 | 6 | protected cache = new Map<string, T[]>(); |
4 | 7 |
|
5 | 8 | protected rule = new Map<string, T[]>(); |
6 | 9 |
|
7 | | - // eslint-disable-next-line class-methods-use-this |
8 | 10 | protected parseURL(url: string): Url | undefined { |
| 11 | + if (url.indexOf("*http") === 0) { |
| 12 | + url = url.substring(1); |
| 13 | + } |
9 | 14 | const match = /^(.+?):\/\/(.*?)((\/.*?)(\?.*?|)|)$/.exec(url); |
10 | 15 | if (match) { |
11 | 16 | return { |
@@ -44,7 +49,7 @@ export default class Match<T> { |
44 | 49 | default: |
45 | 50 | } |
46 | 51 | let pos = u.host.indexOf("*"); |
47 | | - if (u.host === "*") { |
| 52 | + if (u.host === "*" || u.host === "**") { |
48 | 53 | pos = -1; |
49 | 54 | } else if (u.host.endsWith("*")) { |
50 | 55 | // 处理*结尾 |
@@ -104,12 +109,21 @@ export default class Match<T> { |
104 | 109 | return ret; |
105 | 110 | } |
106 | 111 | ret = []; |
107 | | - this.rule.forEach((val, key) => { |
108 | | - const re = new RegExp(key); |
109 | | - if (re.test(url) && ret) { |
110 | | - ret.push(...val); |
111 | | - } |
112 | | - }); |
| 112 | + try { |
| 113 | + this.rule.forEach((val, key) => { |
| 114 | + const re = new RegExp(key); |
| 115 | + if (re.test(url) && ret) { |
| 116 | + ret.push(...val); |
| 117 | + } |
| 118 | + }); |
| 119 | + } catch (e) { |
| 120 | + // eslint-disable-next-line no-console |
| 121 | + console.warn("bad match rule", Logger.E(e)); |
| 122 | + // LoggerCore.getLogger({ component: "match" }).warn( |
| 123 | + // "bad match rule", |
| 124 | + // Logger.E(e) |
| 125 | + // ); |
| 126 | + } |
113 | 127 | this.cache.set(url, ret); |
114 | 128 | return ret; |
115 | 129 | } |
|
0 commit comments