feat(pathDecoder): add support for legacy Windows-style encoded paths
- Enhanced the decodePath and isValidEncodedPath functions to handle legacy Windows format, allowing paths like "C--Users-name-project" to be correctly decoded and validated. - Updated tests to cover the new legacy format, ensuring proper functionality and validation. This commit improves compatibility with legacy path formats, enhancing the utility of the path decoder.
This commit is contained in:
parent
a406f79209
commit
d07485bf27
3 changed files with 30 additions and 0 deletions
|
|
@ -47,6 +47,16 @@ export function decodePath(encodedName: string): string {
|
|||
return '';
|
||||
}
|
||||
|
||||
// Legacy Windows format observed in some Claude installs: "C--Users-name-project"
|
||||
// (no leading dash, drive separator encoded as "--").
|
||||
const legacyWindowsRegex = /^([a-zA-Z])--(.+)$/;
|
||||
const legacyWindowsMatch = legacyWindowsRegex.exec(encodedName);
|
||||
if (legacyWindowsMatch) {
|
||||
const drive = legacyWindowsMatch[1].toUpperCase();
|
||||
const rest = legacyWindowsMatch[2].replace(/-/g, '/');
|
||||
return `${drive}:/${rest}`;
|
||||
}
|
||||
|
||||
// Remove leading dash if present (indicates absolute path)
|
||||
const withoutLeadingDash = encodedName.startsWith('-') ? encodedName.slice(1) : encodedName;
|
||||
|
||||
|
|
@ -96,6 +106,12 @@ export function isValidEncodedPath(encodedName: string): boolean {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Support legacy Windows format: "C--Users-name-project"
|
||||
// (no leading dash, drive separator encoded as "--").
|
||||
if (/^[a-zA-Z]--[a-zA-Z0-9_.\s-]+$/.test(encodedName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Must start with a dash (indicates absolute path)
|
||||
if (!encodedName.startsWith('-')) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,12 @@ describe('ipc guards', () => {
|
|||
expect(result.value).toBe('-C:-Users-test-project');
|
||||
});
|
||||
|
||||
it('accepts legacy Windows-style encoded project IDs', () => {
|
||||
const result = validateProjectId('C--Users-test-project');
|
||||
expect(result.valid).toBe(true);
|
||||
expect(result.value).toBe('C--Users-test-project');
|
||||
});
|
||||
|
||||
it('rejects invalid project IDs', () => {
|
||||
const result = validateProjectId('../escape');
|
||||
expect(result.valid).toBe(false);
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ describe('pathDecoder', () => {
|
|||
it('should decode Windows-style encoded path without adding leading slash', () => {
|
||||
expect(decodePath('-C:-Users-username-projectname')).toBe('C:/Users/username/projectname');
|
||||
});
|
||||
|
||||
it('should decode legacy Windows-style encoded path without leading dash', () => {
|
||||
expect(decodePath('C--Users-username-projectname')).toBe('C:/Users/username/projectname');
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractProjectName', () => {
|
||||
|
|
@ -145,6 +149,10 @@ describe('pathDecoder', () => {
|
|||
expect(isValidEncodedPath('-C:-Users-username-projectname')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for legacy Windows-style encoded path', () => {
|
||||
expect(isValidEncodedPath('C--Users-username-projectname')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for misplaced colons', () => {
|
||||
expect(isValidEncodedPath('-Users-username:project')).toBe(false);
|
||||
expect(isValidEncodedPath('-C:-Users-name-project:extra')).toBe(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue