mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-22 15:51:18 -07:00
refactor: push isValidPath() into parsePastedPaths() (#18664)
This commit is contained in:
committed by
GitHub
parent
da122b1f8a
commit
415cebe904
@@ -42,7 +42,11 @@ describe('escapePath', () => {
|
||||
['double quotes', 'file"name.txt', 'file\\"name.txt'],
|
||||
['hash symbols', 'file#name.txt', 'file\\#name.txt'],
|
||||
['exclamation marks', 'file!name.txt', 'file\\!name.txt'],
|
||||
['tildes', 'file~name.txt', 'file\\~name.txt'],
|
||||
[
|
||||
'tildes',
|
||||
'file~name.txt',
|
||||
process.platform === 'win32' ? 'file~name.txt' : 'file\\~name.txt',
|
||||
],
|
||||
[
|
||||
'less than and greater than signs',
|
||||
'file<name>.txt',
|
||||
@@ -99,11 +103,16 @@ describe('escapePath', () => {
|
||||
expect(escapePath('')).toBe('');
|
||||
});
|
||||
|
||||
it('should handle paths with only special characters', () => {
|
||||
expect(escapePath(' ()[]{};&|*?$`\'"#!~<>')).toBe(
|
||||
'\\ \\(\\)\\[\\]\\{\\}\\;\\&\\|\\*\\?\\$\\`\\\'\\"\\#\\!\\~\\<\\>',
|
||||
it('should handle paths with multiple special characters', () => {
|
||||
expect(escapePath(' ()[]{};&|*?$`\'"#!<>')).toBe(
|
||||
'\\ \\(\\)\\[\\]\\{\\}\\;\\&\\|\\*\\?\\$\\`\\\'\\"\\#\\!\\<\\>',
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle tildes based on platform', () => {
|
||||
const expected = process.platform === 'win32' ? '~' : '\\~';
|
||||
expect(escapePath('~')).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('unescapePath', () => {
|
||||
@@ -130,12 +139,12 @@ describe('unescapePath', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle all special characters', () => {
|
||||
it('should handle all special characters but tilda', () => {
|
||||
expect(
|
||||
unescapePath(
|
||||
'\\ \\(\\)\\[\\]\\{\\}\\;\\&\\|\\*\\?\\$\\`\\\'\\"\\#\\!\\~\\<\\>',
|
||||
'\\ \\(\\)\\[\\]\\{\\}\\;\\&\\|\\*\\?\\$\\`\\\'\\"\\#\\!\\<\\>',
|
||||
),
|
||||
).toBe(' ()[]{};&|*?$`\'"#!~<>');
|
||||
).toBe(' ()[]{};&|*?$`\'"#!<>');
|
||||
});
|
||||
|
||||
it('should be the inverse of escapePath', () => {
|
||||
|
||||
@@ -16,10 +16,12 @@ export const GOOGLE_ACCOUNTS_FILENAME = 'google_accounts.json';
|
||||
|
||||
/**
|
||||
* Special characters that need to be escaped in file paths for shell compatibility.
|
||||
* Includes: spaces, parentheses, brackets, braces, semicolons, ampersands, pipes,
|
||||
* asterisks, question marks, dollar signs, backticks, quotes, hash, and other shell metacharacters.
|
||||
* Note that windows doesn't escape tilda.
|
||||
*/
|
||||
export const SHELL_SPECIAL_CHARS = /[ \t()[\]{};|*?$`'"#&<>!~]/;
|
||||
export const SHELL_SPECIAL_CHARS =
|
||||
process.platform === 'win32'
|
||||
? /[ \t()[\]{};|*?$`'"#&<>!]/
|
||||
: /[ \t()[\]{};|*?$`'"#&<>!~]/;
|
||||
|
||||
/**
|
||||
* Returns the home directory.
|
||||
|
||||
Reference in New Issue
Block a user