Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doctoc crashes when space in filename #127

Closed
keverw opened this issue Mar 13, 2017 · 7 comments · Fixed by #248
Closed

doctoc crashes when space in filename #127

keverw opened this issue Mar 13, 2017 · 7 comments · Fixed by #248

Comments

@keverw
Copy link

keverw commented Mar 13, 2017

doctoc 'README - add to.md'
fs.js:907
  return binding.stat(pathModule._makeLong(path));
                 ^

Error: ENOENT: no such file or directory, stat 'README\ -\ add\ to.md'
    at Object.fs.statSync (fs.js:907:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/doctoc/doctoc.js:103:17)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)

I'm not too sure how important this bug would be, as it seems like not using spaces is better anyways. Discovered this when asking for help on #80

@jez
Copy link
Collaborator

jez commented Mar 13, 2017

As far as I can tell, this is the offending line. It looks to have been introduced by this commit: 994839f.

@thlorenz: The message for that commit makes it look like this line was added intentionally. Is it safe to remove this line, or is there something else we should be aware of?

To explain further, it seems like we manually escape spaces in filenames, which in turn causes fs.statFile to fail, because it looks for a file named 'foo\ bar.md' instead of 'foo bar.md'.

@thlorenz
Copy link
Owner

@jez I think we should write a test that shows the problem and make sure it gets fixed by removing the offending line.
Afaik escaping spaces should only be necessary directly on the command line, but since this gets handled by node fs module we shouldn't need to.

I added that line myself and can't quite remember the reasoning behind it.

@jez
Copy link
Collaborator

jez commented Mar 13, 2017

I think we should write a test that shows the problem and make sure it gets fixed by removing the offending line.

Our testing infrastructure currently doesn't test any of the argument parsing or IO code, does it?

@andrii-kovalenko-ct
Copy link

Got this issue today, pls - fix

@drjasonharrison
Copy link

As a pre-commit hook doctoc v2.2.0 crashes like this:

node:internal/fs/utils:345
    throw err;
    ^

Error: ENOENT: no such file or directory, stat 'processor/find-2022-05\ copy.md'
    at Object.statSync (node:fs:1551:3)
    at Object.<anonymous> (/home/jason/.cache/pre-commit/repofjq0vp2t/node_env-default/lib/node_modules/doctoc/doctoc.js:113:17)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: 'processor/find-2022-05\\ copy.md'
}

Node.js v17.7.1

@thlorenz
Copy link
Owner

Our testing infrastructure currently doesn't test any of the argument parsing or IO code, does it?

No it does not, so we'd need to setup CLI tests for this @jez . I understand if that's a bit much to ask, but would be great to have also going forward.

Otherwise we could just fix the issue for now without the test.

@alf-p-steinbach
Copy link

alf-p-steinbach commented Aug 11, 2023

In Windows a workaround is to use the DOS 8+3 shortname. The shortnames are shown by Cmd dir /x and can be obtained e.g. via the for command:

[T:\]
> for %f in ("*.md") do @echo "%f" → "%~sf"
"00 about.md" → "T:\00ABOU~1.MD"
"01 Preparation.md" → "T:\01PREP~1.MD"

A different workaround could be to use hard or symbolic links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants