Skip to content

Commit

Permalink
feat: add url config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaytonXu committed Nov 30, 2024
1 parent 492debf commit 816e70f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/hexo/validate_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export = (ctx: Hexo): void => {
try {
// eslint-disable-next-line no-new
new URL(config.url);
// eslint-disable-next-line no-new
new URL('source/_post/xxx', config.url);
} catch {
throw new TypeError('Invalid config detected: "url" should be a valid URL!');
}
Expand Down
14 changes: 14 additions & 0 deletions test/scripts/hexo/validate_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ describe('Validate config', () => {
}
});


it('config.url - not start with xx://', () => {
// @ts-ignore
hexo.config.url = 'localhost:4000';

try {
validateConfig(hexo);
should.fail();
} catch (e) {
e.name.should.eql('TypeError');
e.message.should.eql('Invalid config detected: "url" should be a valid URL!');
}
});

// #4510
it('config.url - slash', () => {
hexo.config.url = '/';
Expand Down

0 comments on commit 816e70f

Please sign in to comment.