diff --git a/lib/hexo/validate_config.ts b/lib/hexo/validate_config.ts index c7ca6477bd..52cd6ab5e3 100644 --- a/lib/hexo/validate_config.ts +++ b/lib/hexo/validate_config.ts @@ -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!'); } diff --git a/test/scripts/hexo/validate_config.ts b/test/scripts/hexo/validate_config.ts index c414c2a68d..f64d43a22a 100644 --- a/test/scripts/hexo/validate_config.ts +++ b/test/scripts/hexo/validate_config.ts @@ -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 = '/';