diff --git a/common.mjs b/common.mjs index c6edabd..3956960 100644 --- a/common.mjs +++ b/common.mjs @@ -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位的英文字符串 diff --git a/test/common.test.mjs b/test/common.test.mjs index baca849..1a4539f 100644 --- a/test/common.test.mjs +++ b/test/common.test.mjs @@ -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); }); \ No newline at end of file