chore: stricter validation (#12409)

This commit is contained in:
Tony 2023-04-29 01:28:38 +04:00 committed by GitHub
parent 2e2c0058a8
commit 1d7f3bfe04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 42 additions and 23 deletions

View File

@ -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') {

View File

@ -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') ?? ''

View File

@ -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')}`,
},
],

View File

@ -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',
},
],

View File

@ -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',
},
],

View File

@ -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',
},
],

View File

@ -17,7 +17,7 @@ module.exports = {
{
title: '用户订阅列表',
docs: 'https://docs.rsshub.app/anime.html#iwara',
source: '',
source: '/',
target: '/iwara/subscriptions',
},
],

View File

@ -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',
},
],

View File

@ -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',
},
],

View File

@ -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',
},
{

View File

@ -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',
},
],

View File

@ -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',
},
{