Browse Source

url check improved

master
filesite 6 months ago
parent
commit
a1d10645b4
  1. 2
      common.mjs
  2. 26
      test/common.test.mjs

2
common.mjs

@ -133,7 +133,7 @@ class Common { @@ -133,7 +133,7 @@ class Common {
//检查url是否符合要求
isUrlOk(url) {
return /^http(s)?:\/\/[\w\-\.\/:\?]{6,100}$/i.test(url);
return /^http(s)?:\/\/[\w\-\.\/:\?\=]{6,100}$/i.test(url);
}
//检查uuid是否符合要求:6-32位的英文字符串

26
test/common.test.mjs

@ -139,4 +139,30 @@ test('Common function saveLog test', async (t) => { @@ -139,4 +139,30 @@ test('Common function saveLog test', async (t) => {
filename = './logs/test.log';
saved = await common.saveLog(filename, JSON.stringify(data));
assert.equal(saved, false);
});
test('Common function isUrlOk test', async (t) => {
let url = 'https://www.bilibili.com/video/BV1AM41137LB/?share_source=copy_web';
let urlOk = common.isUrlOk(url);
assert.equal(urlOk, true);
//case 2
url = 'https://www.bilibili.com/video/BV1AM41137LB/';
urlOk = common.isUrlOk(url);
assert.equal(urlOk, true);
//case 3
url = 'http://127.0.0.1:8080/video/BV1AM41137LB.html';
urlOk = common.isUrlOk(url);
assert.equal(urlOk, true);
//case 4
url = '//127.0.0.1:8080/video/BV1AM41137LB.html';
urlOk = common.isUrlOk(url);
assert.equal(urlOk, false);
//case 5
url = 'https://www.bil-ibili.com/video/BV1AM4_1137LB/';
urlOk = common.isUrlOk(url);
assert.equal(urlOk, true);
});
Loading…
Cancel
Save