Files
monkey-ai-web/src/helpers/safeUrl.test.js
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

30 lines
736 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { toSafeHttpUrl } from './safeUrl.js';
test('toSafeHttpUrl keeps absolute http(s) urls only', () => {
assert.equal(
toSafeHttpUrl(' https://ai.example.com/ '),
'https://ai.example.com/',
);
assert.equal(toSafeHttpUrl('http://10.0.0.5:8080'), 'http://10.0.0.5:8080');
for (const bad of [
'',
null,
undefined,
42,
'javascript:alert(1)',
'JAVASCRIPT:alert(1)',
'data:text/html,x',
'file:///etc/passwd',
'//evil.example.com',
'/relative/path',
'ai.example.com',
'https://',
'https://user:pw@ai.example.com',
]) {
assert.equal(toSafeHttpUrl(bad), '', `${bad} must be rejected`);
}
});