diff --git a/packages/vscode/test/grammar/test.mjs b/packages/vscode/test/grammar/test.mjs index e67cace5..02d69959 100644 --- a/packages/vscode/test/grammar/test.mjs +++ b/packages/vscode/test/grammar/test.mjs @@ -15,37 +15,6 @@ const grammars = readdirSync(grammarDir) const allGrammars = [...grammars, ...dummyGrammars]; -/** - * Escapes command line arguments for Windows - * @param {string} arg - * @returns {string} - * - * Escaping sequences obtained trusting https://www.robvanderwoude.com/escapechars.php#:~:text=In%20batch%20files%2C%20the%20percent,instead%20of%20being%20further%20interpreted. - */ -function escapeWindowsArg(arg) { - // If the argument doesn't contain spaces or special characters, return it as is - const single_charac_escape = /(['`,;=()<>|&^])/g; - const double_carat_escape = /(!)/g; - const percentage_escape = /(%)/g; - const backlash_escape = /([\\"[\].*?])/g; - if ( - ![single_charac_escape, double_carat_escape, percentage_escape, backlash_escape].some((regex) => - regex.test(arg), - ) - ) { - return arg; - } - - // This one must go first, since it would otherwise conflict with the ! rule - arg = arg.replace(single_charac_escape, '^$1'); - arg = arg.replace(double_carat_escape, '^^$1'); - arg = arg.replace(percentage_escape, '%$1'); - arg = arg.replace(backlash_escape, '\\$1'); - - // Wrap the entire argument in double quotes - return `"${arg}"`; -} - /** * @param {Parameters} arg * @returns {Promise} @@ -75,15 +44,10 @@ async function snapShotTest() { './test/grammar/fixtures/**/*.astro', ...allGrammars.reduce((/** @type string[] */ previous, path) => [...previous, '-g', path], []), ...extraArgs, - ].map((arg) => { - if (isWindows) return escapeWindowsArg(arg); - return arg; - }); + ].map((arg) => (isWindows && arg.includes(' ') ? `"${arg}"` : arg)) const code = await promisifySpawn(isWindows ? 'pnpm.cmd' : 'pnpm', args, { stdio: 'inherit', - // windows shell escaping on nodejs doesn't work - // See https://github.com/nodejs/node/issues/52554 and https://github.com/withastro/language-tools/pull/893 shell: isWindows, });