(url: string, rules: URLRuleEntry[])
| 91 | // 检查单一网址是否符合 Inclusion 原则 |
| 92 | // 即匹配任一@include/@match且不匹配任何@exclude |
| 93 | export function isUrlIncluded(url: string, rules: URLRuleEntry[]): boolean { |
| 94 | let anyInclusionRule = false; |
| 95 | let anyExclusionRule = false; |
| 96 | for (const rule of rules) { |
| 97 | if (rule.ruleType & RuleTypeBit.INCLUSION) { |
| 98 | // include |
| 99 | if (!anyInclusionRule && isUrlMatch(url, rule)) { |
| 100 | // 符合 inclusion |
| 101 | anyInclusionRule = true; |
| 102 | } |
| 103 | } else { |
| 104 | // exclude |
| 105 | if (!isUrlMatch(url, rule)) { |
| 106 | // 符合 exclusion |
| 107 | anyExclusionRule = true; |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | // true 条件: ( Any @include/@match = true ) AND ( All @exclude = false ) |
| 113 | return anyInclusionRule && !anyExclusionRule; |
| 114 | } |
| 115 | |
| 116 | // 检查单一网址是否符合 Exclusion 原则 |
| 117 | // 即匹配任何@exclude或所有@include/@match皆不匹配 |
no test coverage detected