From 2ec86827f58b8d4ab22634be998b42bfbd3e0478 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Sat, 26 Nov 2022 15:41:05 +0800 Subject: [PATCH] fix: fix #4334 --- lib/plugins/console/new.js | 5 +++++ test/scripts/console/new.js | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.js index 3b5942c98b..f96ea1c74b 100644 --- a/lib/plugins/console/new.js +++ b/lib/plugins/console/new.js @@ -33,6 +33,11 @@ function newConsole(args) { path: args.p || args.path }; + // fix #4334 + if (data.path) { + data.path = String(data.path); + } + const keys = Object.keys(args); for (let i = 0, len = keys.length; i < len; i++) { diff --git a/test/scripts/console/new.js b/test/scripts/console/new.js index e578a2d047..d9ed384db0 100644 --- a/test/scripts/console/new.js +++ b/test/scripts/console/new.js @@ -136,6 +136,28 @@ describe('new', () => { await unlink(path); }); + // fix #4334 + it('path with numbers', async () => { + const date = moment(now); + const path = join(hexo.source_dir, '_posts', '404.md'); + const body = [ + 'title: Hello World', + 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), + 'tags:', + '---' + ].join('\n') + '\n'; + + await n({ + _: ['Hello World'], + slug: 'foo', + path: 404 + }); + const content = await readFile(path); + content.should.eql(body); + + await unlink(path); + }); + it('path - p', async () => { const date = moment(now); const path = join(hexo.source_dir, '_posts', 'bar.md');