From 1d7f3bfe04310bd2e7e1092b2a7168b1132572a7 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 29 Apr 2023 01:28:38 +0400 Subject: [PATCH] chore: stricter validation (#12409) --- lib/radar.js | 25 ++++++++++++++++++++++--- lib/v2/atcoder/radar.js | 2 +- lib/v2/chinathinktanks/radar.js | 2 +- lib/v2/embassy/radar.js | 2 +- lib/v2/gov/radar.js | 2 +- lib/v2/ithome/radar.js | 6 +++--- lib/v2/iwara/radar.js | 2 +- lib/v2/rsshub/radar.js | 4 ++-- lib/v2/sspai/radar.js | 2 +- lib/v2/zcool/radar.js | 12 ++++++------ lib/v2/zhihu/radar.js | 4 ++-- lib/v2/zju/radar.js | 2 +- 12 files changed, 42 insertions(+), 23 deletions(-) diff --git a/lib/radar.js b/lib/radar.js index e97081991..0766e3ab9 100644 --- a/lib/radar.js +++ b/lib/radar.js @@ -43,9 +43,28 @@ const validateRadarRules = (rule, dir) => { if (!item.docs.startsWith('https://docs.rsshub.app/')) { throw Error(`Radar rules for "${host}" in "${dir}" should start with 'https://docs.rsshub.app/'.`); } - if ((Array.isArray(item.source) && item.source.some((s) => s.includes('#') || s.includes('='))) || (typeof item.source === 'string' && (item.source.includes('#') || item.source.includes('=')))) { - // Some will try to match '/some/path?a=1' which is not supported - throw Error(`Radar rules for "${host}" in "${dir}" cannot match URL hash or URL search parameters.`); + if (Array.isArray(item.source)) { + if (!item.source.length) { + // check for [] + throw Error(`Radar rule of "${item.title}" for subdomain "${host}" in "${dir}" should not be empty.`); + } + if (item.source.some((s) => s.includes('#') || s.includes('='))) { + // Some will try to match '/some/path?a=1' which is not supported + throw Error(`Radar rule of "${item.title}" for subdomain "${host}" in "${dir}" cannot match URL hash or URL search parameters.`); + } + if (item.source.some((s) => !s.length)) { + // check for ['/some/thing', ''] and [''] + throw Error(`Radar rule of "${item.title}" for subdomain "${host}" in "${dir}" should not be empty.`); + } + } + if (typeof item.source === 'string') { + if (!item.source.length) { + // check for '' + throw Error(`Radar rule of "${item.title}" for subdomain "${host}" in "${dir}" should not be empty.`); + } + if (item.source.includes('#') || item.source.includes('=')) { + throw Error(`Radar rule of "${item.title}" for subdomain "${host}" in "${dir}" cannot match URL hash or URL search parameters.`); + } } for (const key in item) { if (key !== 'title' && key !== 'docs' && key !== 'source' && key !== 'target') { diff --git a/lib/v2/atcoder/radar.js b/lib/v2/atcoder/radar.js index 5581fc976..c473e9f69 100644 --- a/lib/v2/atcoder/radar.js +++ b/lib/v2/atcoder/radar.js @@ -11,7 +11,7 @@ module.exports = { { title: 'Contests', docs: 'https://docs.rsshub.app/programming.html#atcoder-contests', - source: ['/contests/archive', '/contests', ''], + source: ['/contests/archive', '/contests'], target: (params, url) => `/atcoder/content/${new URL(url).searchParams.get('lang') ?? 'en'}/${new URL(url).searchParams.get('ratedType') ?? '0'}/${new URL(url).searchParams.get('category') ?? '0'}/${ new URL(url).searchParams.get('keyword') ?? '' diff --git a/lib/v2/chinathinktanks/radar.js b/lib/v2/chinathinktanks/radar.js index 28f5a4e8f..587c377ff 100644 --- a/lib/v2/chinathinktanks/radar.js +++ b/lib/v2/chinathinktanks/radar.js @@ -5,7 +5,7 @@ module.exports = { { title: '观点与实践', docs: 'https://docs.rsshub.app/study.html#zhong-guo-zhi-ku-wang', - source: '', + source: '/', target: (params, url) => `/chinathinktanks/${new URL(url).searchParams.get('id')}`, }, ], diff --git a/lib/v2/embassy/radar.js b/lib/v2/embassy/radar.js index 12a8a367e..4612f11e1 100644 --- a/lib/v2/embassy/radar.js +++ b/lib/v2/embassy/radar.js @@ -226,7 +226,7 @@ module.exports = { { title: '通知公告 - 名古屋总领事馆', docs: 'https://docs.rsshub.app/government.html#zhong-guo-zhu-wai-shi-ling-guan', - source: '', + source: '/', target: '/embassy/jp/nagoya', }, ], diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js index 347b394f5..d1355eee1 100644 --- a/lib/v2/gov/radar.js +++ b/lib/v2/gov/radar.js @@ -589,7 +589,7 @@ module.exports = { { title: '获取国家医师资格考试通知', docs: 'https://docs.rsshub.app/government.html#ji-nan-shi-wei-sheng-jian-kang-wei-yuan-hui', - source: ['', '/*'], + source: ['/*'], target: '/gov/jinan/healthcommission/medical_exam_notice', }, ], diff --git a/lib/v2/ithome/radar.js b/lib/v2/ithome/radar.js index c45eee24a..27f2322ea 100644 --- a/lib/v2/ithome/radar.js +++ b/lib/v2/ithome/radar.js @@ -17,19 +17,19 @@ module.exports = { { title: '24 小时阅读榜', docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang', - source: ['', '/*'], + source: ['/*'], target: '/ithome/ranking/24h', }, { title: '7 天最热', docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang', - source: ['', '/*'], + source: ['/*'], target: '/ithome/ranking/7days', }, { title: '月榜', docs: 'https://docs.rsshub.app/new-media.html#it-zhi-jia-re-bang', - source: ['', '/*'], + source: ['/*'], target: '/ithome/ranking/monthly', }, ], diff --git a/lib/v2/iwara/radar.js b/lib/v2/iwara/radar.js index 18c1d2a7e..5b8fdde0b 100644 --- a/lib/v2/iwara/radar.js +++ b/lib/v2/iwara/radar.js @@ -17,7 +17,7 @@ module.exports = { { title: '用户订阅列表', docs: 'https://docs.rsshub.app/anime.html#iwara', - source: '', + source: '/', target: '/iwara/subscriptions', }, ], diff --git a/lib/v2/rsshub/radar.js b/lib/v2/rsshub/radar.js index 71cb78f84..fc56e1c37 100644 --- a/lib/v2/rsshub/radar.js +++ b/lib/v2/rsshub/radar.js @@ -5,13 +5,13 @@ module.exports = { { title: '有新路由啦', docs: 'https://docs.rsshub.app/program-update.html#rsshub', - source: ['', '/*tpath'], + source: ['/*'], target: '/rsshub/routes', }, { title: '有新赞助商啦', docs: 'https://docs.rsshub.app/program-update.html#rsshub', - source: ['', '/*tpath'], + source: ['/*'], target: '/rsshub/sponsors', }, ], diff --git a/lib/v2/sspai/radar.js b/lib/v2/sspai/radar.js index 31dce970c..59c647b36 100644 --- a/lib/v2/sspai/radar.js +++ b/lib/v2/sspai/radar.js @@ -73,7 +73,7 @@ module.exports = { { title: 'Shortcuts Gallery', docs: 'https://docs.rsshub.app/new-media.html#shao-shu-pai-sspai', - source: ['', '/*tpath'], + source: ['/*'], target: '/sspai/shortcuts', }, ], diff --git a/lib/v2/zcool/radar.js b/lib/v2/zcool/radar.js index 5ffd208c1..df2782f74 100644 --- a/lib/v2/zcool/radar.js +++ b/lib/v2/zcool/radar.js @@ -11,37 +11,37 @@ module.exports = { { title: '发现 - 精选 - 全部推荐', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/discover/all', }, { title: '发现 - 精选 - 首页推荐', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/discover/home', }, { title: '发现 - 精选 - 编辑精选', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/discover/home', }, { title: '发现 - 精选 - 文章 - 编辑精选', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/discover/article', }, { title: '作品榜单', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/top/design', }, { title: '文章榜单', docs: 'https://docs.rsshub.app/design.html#zhan-ku', - source: '', + source: '/', target: '/zcool/top/article', }, { diff --git a/lib/v2/zhihu/radar.js b/lib/v2/zhihu/radar.js index 8bf6f289b..b85278a5d 100644 --- a/lib/v2/zhihu/radar.js +++ b/lib/v2/zhihu/radar.js @@ -93,13 +93,13 @@ module.exports = { { title: '日报', docs: 'https://docs.rsshub.app/social-media.html#zhi-hu', - source: '', + source: '/', target: '/zhihu/daily', }, { title: '日报', docs: 'https://docs.rsshub.app/social-media.html#zhi-hu', - source: '/*tpath', + source: '/*', target: '/zhihu/daily', }, ], diff --git a/lib/v2/zju/radar.js b/lib/v2/zju/radar.js index 81f1d65fd..85033d8fb 100644 --- a/lib/v2/zju/radar.js +++ b/lib/v2/zju/radar.js @@ -46,7 +46,7 @@ module.exports = { { title: '软件学院 - 全部通知', docs: 'https://docs.rsshub.app/university.html#zhe-jiang-da-xue', - source: ['', '/*tpath'], + source: ['/*'], target: '/zju/cst/0', }, {