hexo icon indicating copy to clipboard operation
hexo copied to clipboard

fix: create post with a path composed of numbers throw an error

Open D-Sketon opened this issue 2 years ago • 8 comments

What does it do?

fix #4334

Screenshots

Pull request tasks

  • [x] Add test cases for the changes.
  • [x] Passed the CI test.

D-Sketon avatar Nov 26 '22 07:11 D-Sketon

How to test

git clone -b fix_4334 https://github.com/D-Sketon/hexo.git
cd hexo
npm install
npm test

github-actions[bot] avatar Nov 26 '22 07:11 github-actions[bot]

Coverage Status

Coverage increased (+0.04%) to 98.778% when pulling 2ec86827f58b8d4ab22634be998b42bfbd3e0478 on D-Sketon:fix_4334 into 58a8f8c4147782f6d8719abb00cfd91323688ec1 on hexojs:master.

coveralls avatar Nov 26 '22 07:11 coveralls

There will be an edge case: --path 0x100 will become string '256', not '0x100'.

You can try to change the code here: https://github.com/hexojs/hexo-cli/blob/5c5fc8fe2fc781a557a30f1bf2043502825f173c/lib/hexo.ts#L18

minimist(process.argv.slice(2), { string: ['_', 'p', 'path'] })

should work

stevenjoezhang avatar Nov 27 '22 08:11 stevenjoezhang

See also https://github.com/hexojs/hexo-cli/pull/200

stevenjoezhang avatar Nov 27 '22 08:11 stevenjoezhang

@stevenjoezhang should slug also be added to this code? For example: hexo new page --slug 0x404 will generate 1028.md

D-Sketon avatar Nov 27 '22 08:11 D-Sketon

@D-Sketon Yes, the slug should also have a string type

You can add other test cases like https://github.com/hexojs/hexo/pull/4363

stevenjoezhang avatar Nov 27 '22 09:11 stevenjoezhang

@stevenjoezhang I'm a bit confused, do I just need to add extra test cases in this PR? I have tried to add test cases like #4363, but they all fail. It seems that the tests all skip hexo-cli by using lib\plugins\console\new.js directly

D-Sketon avatar Nov 27 '22 11:11 D-Sketon

It's tricky to cover this situation with unit tests, need to hook process.argv somehow

stevenjoezhang avatar Nov 29 '22 16:11 stevenjoezhang

Superseded by #5465

D-Sketon avatar Apr 14 '24 12:04 D-Sketon