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

convertPathToPattern not converting some\\@directory\\ correctly #452

Open
AriPerkkio opened this issue Jul 29, 2024 · 2 comments
Open

convertPathToPattern not converting some\\@directory\\ correctly #452

AriPerkkio opened this issue Jul 29, 2024 · 2 comments

Comments

@AriPerkkio
Copy link

AriPerkkio commented Jul 29, 2024

Environment

  • OS Version: Windows 11
  • Node.js Version: 20.15.0

Works fine on non-Windows, e.g. Mac. convertPathToPattern checks OS so reproduces only on Windows.

Actual behavior

const resolved = path.join(require.resolve("@vitest/coverage-v8"), "..");
const pattern = fg.convertPathToPattern(resolved) + "/**";
const files = fg.globSync(pattern);

//  resolved: 'C:\\Users\\Ari\\git\\fastglob\\node_modules\\@vitest\\coverage-v8\\dist',
//  pattern: 'C:/Users/Ari/git/fastglob/node_modules\\@vitest/coverage-v8/dist/**',
//                                                  ^^^
//  files: []

Expected behavior

//  resolved: 'C:\\Users\\Ari\\git\\fastglob\\node_modules\\@vitest\\coverage-v8\\dist',
//  pattern: 'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/**',
//                                                  ^^
//  files: [
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/index.d.ts',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/index.js',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/provider.d.ts',
//    'C:/Users/Ari/git/fastglob/node_modules/@vitest/coverage-v8/dist/provider.js'
// ]

Steps to reproduce

  1. npm init
  2. npm i -D fast-glob @vitest/coverage-v8
  3. Save code sample to index.js
  4. node index.js

Code sample

const path = require("node:path");
const fg = require("fast-glob");

const resolved = path.join(require.resolve("@vitest/coverage-v8"), "..");
const pattern = fg.convertPathToPattern(resolved) + "/**";
const files = fg.globSync(pattern);

console.log({
  resolved,
  pattern,
  files,

  fixedPattern: pattern.replaceAll("\\@", "/@"),
  fixed: fg.globSync(pattern.replaceAll("\\@", "/@")),
});

image

@AriPerkkio
Copy link
Author

I see that https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#convertpathtopatternpath does mention @ and backslash using as espace characters. In this case \\@ is not escape for @, right? In \@ it would be?

@mrmlnc
Copy link
Owner

mrmlnc commented Nov 23, 2024

The problem here is that \\@ is considered an already escaped special character. Otherwise, double character escaping will be applied here.

The goal of this task is to learn how to differentiate between a path separator and a special character, when the special character follows the path separator in the path.

it.only('should convert slashes after the path separator', () => {
	assert.strictEqual(util.convertWindowsPathToPattern('\\@'), '/@');
	assert.strictEqual(util.convertWindowsPathToPattern('\\\\@'), '/\\@');
});

And… I'm not sure there is a way to solve this problem.

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

No branches or pull requests

2 participants