fix: exclude prose colons from drainage URL boundaries
CSS quality / css-quality (push) Has been cancelled
CSS quality / css-quality (push) Has been cancelled
This commit is contained in:
@@ -30,6 +30,28 @@ const material = (id: string, url: string, channels: string[], auditStatus = 'ap
|
||||
})),
|
||||
});
|
||||
describe('drainage authorization', () => {
|
||||
it.each(['详情:https://qa0915.example.com', '详情:https://qa0915.example.com'])(
|
||||
'keeps prose separators outside explicit URLs: %s',
|
||||
(content) => {
|
||||
const text = 'https://qa0915.example.com';
|
||||
const start = content.indexOf(text);
|
||||
const targets = drainageTargets(content, [
|
||||
{
|
||||
ruleId: 'url',
|
||||
ruleCode: 'URL',
|
||||
ruleName: 'URL',
|
||||
category: 'url',
|
||||
text,
|
||||
normalizedText: text,
|
||||
start,
|
||||
end: start + text.length,
|
||||
},
|
||||
]);
|
||||
expect(targets).toHaveLength(1);
|
||||
expect(targets[0].text).toBe(text);
|
||||
expect(materialMatches(targets[0], text)).toBe(true);
|
||||
},
|
||||
);
|
||||
test.each([
|
||||
'lisglo.cn',
|
||||
'sms.lisglo.cn',
|
||||
|
||||
@@ -81,7 +81,11 @@ export function drainageTargets(content: string, matches: DrainageDetectionMatch
|
||||
if (start < 0 || end <= 0) throw new ServiceUnavailableException('引流识别位置无效');
|
||||
// Extend the entire URL token, including suffix labels, userInfo and query.
|
||||
const token = /[a-z0-9:/?&=.%_+@#~!$*()[\]-]/i;
|
||||
while (start > 0 && token.test(normalized.text[start - 1])) start--;
|
||||
while (start > 0 && token.test(normalized.text[start - 1])) {
|
||||
// A prose colon before an explicit scheme is a separator, including normalized Chinese colons.
|
||||
if (normalized.text[start - 1] === ':' && /^https?:\/\//i.test(normalized.text.slice(start, end))) break;
|
||||
start--;
|
||||
}
|
||||
while (end < normalized.text.length && token.test(normalized.text[end])) end++;
|
||||
const text = normalized.text.slice(start, end).replace(/[.,;!]+$/, '');
|
||||
const value = drainageHost(text);
|
||||
|
||||
Reference in New Issue
Block a user