mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 22:03:45 +00:00
fix(coding-agent): handle macOS filenames with curly quotes and NFD Unicode
Fixes #1078 - Add tryNFDVariant() to normalize paths to NFD form - Add tryCurlyQuoteVariant() to convert straight quotes to curly quotes - Try combined NFD + curly quote variant for French macOS screenshots - Add comprehensive tests for path-utils
This commit is contained in:
parent
93c39faa93
commit
4edb506df8
3 changed files with 186 additions and 3 deletions
|
|
@ -12,6 +12,17 @@ function tryMacOSScreenshotPath(filePath: string): string {
|
|||
return filePath.replace(/ (AM|PM)\./g, `${NARROW_NO_BREAK_SPACE}$1.`);
|
||||
}
|
||||
|
||||
function tryNFDVariant(filePath: string): string {
|
||||
// macOS stores filenames in NFD (decomposed) form, try converting user input to NFD
|
||||
return filePath.normalize("NFD");
|
||||
}
|
||||
|
||||
function tryCurlyQuoteVariant(filePath: string): string {
|
||||
// macOS uses U+2019 (right single quotation mark) in screenshot names like "Capture d'écran"
|
||||
// Users typically type U+0027 (straight apostrophe)
|
||||
return filePath.replace(/'/g, "\u2019");
|
||||
}
|
||||
|
||||
function fileExists(filePath: string): boolean {
|
||||
try {
|
||||
accessSync(filePath, constants.F_OK);
|
||||
|
|
@ -51,9 +62,28 @@ export function resolveReadPath(filePath: string, cwd: string): string {
|
|||
return resolved;
|
||||
}
|
||||
|
||||
const macOSVariant = tryMacOSScreenshotPath(resolved);
|
||||
if (macOSVariant !== resolved && fileExists(macOSVariant)) {
|
||||
return macOSVariant;
|
||||
// Try macOS AM/PM variant (narrow no-break space before AM/PM)
|
||||
const amPmVariant = tryMacOSScreenshotPath(resolved);
|
||||
if (amPmVariant !== resolved && fileExists(amPmVariant)) {
|
||||
return amPmVariant;
|
||||
}
|
||||
|
||||
// Try NFD variant (macOS stores filenames in NFD form)
|
||||
const nfdVariant = tryNFDVariant(resolved);
|
||||
if (nfdVariant !== resolved && fileExists(nfdVariant)) {
|
||||
return nfdVariant;
|
||||
}
|
||||
|
||||
// Try curly quote variant (macOS uses U+2019 in screenshot names)
|
||||
const curlyVariant = tryCurlyQuoteVariant(resolved);
|
||||
if (curlyVariant !== resolved && fileExists(curlyVariant)) {
|
||||
return curlyVariant;
|
||||
}
|
||||
|
||||
// Try combined NFD + curly quote (for French macOS screenshots like "Capture d'écran")
|
||||
const nfdCurlyVariant = tryCurlyQuoteVariant(nfdVariant);
|
||||
if (nfdCurlyVariant !== resolved && fileExists(nfdCurlyVariant)) {
|
||||
return nfdCurlyVariant;
|
||||
}
|
||||
|
||||
return resolved;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue