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

CLI fails to handle Windows directory separators in command-line arguments #175

Closed
fredrikhr opened this issue Jan 14, 2022 · 6 comments
Closed

Comments

@fredrikhr
Copy link
Contributor

When running the httpyac CLI on Windows, if you specify a path to a file that contains windows directory separators, i.e. \, the CLI fails to locate the http file even if it exists and exits with an error message that states that the specified file could not be found.

> npx httpyac "path\to\file.http"
httpYac cannot find the specified file path\\to\\file.http.

Whether the path argument is quoted or not does not change the behaviour if quoting is not necessary by the shell.

This happens in all cases where the path contains a directory separator, i.e.:

  • .\file-in-current-dir.http
  • subdir\file-in-subdir-relative-to-current-dir.http
  • C:\absolute-path-dir\file-in-absolute-dir.http

If you replace the windows-directory separator with a *NIX-like / the CLI finds the file and executes it as expected.

If you execute the CLI from the directory the file is located in and specify only the file name, the path specified to the CLI no longer contains directory separators, and thus the CLI also find the file and executes it as expected.

@AnWeber
Copy link
Owner

AnWeber commented Jan 17, 2022

Error is triggered by globby/fast-glob (see sindresorhus/globby#130). The syntax only allows / and no \. I will replace the \ with correct / if no files were found.

@fredrikhr
Copy link
Contributor Author

But is that better? AFAIK, \ is a legal escaping character in *NIX-like systems?

@AnWeber
Copy link
Owner

AnWeber commented Jan 18, 2022

That's why the search for the files first. If no file was found, it was not an escape attempt. I could only add a restriction to Windows systems. That would probably be even better.

@fredrikhr
Copy link
Contributor Author

I would do

const path = require('path');

if (path.sep !== '/') {
  glob_path = original_path.replaceAll(path.sep, '/');
} else {
  glob_path = original_path;
}

@AnWeber
Copy link
Owner

AnWeber commented Jan 18, 2022

And replaceAll is only available from NodeJS v15. But otherwise I use your suggestion

AnWeber added a commit that referenced this issue Jan 18, 2022
@AnWeber
Copy link
Owner

AnWeber commented Jan 27, 2022

Update with this change is published. thx

@AnWeber AnWeber closed this as completed Jan 27, 2022
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

No branches or pull requests

2 participants