ec882214e2
Address code review feedback: - Extract normalizeFileUri to mobile/src/utils/normalizeUri.ts - Import shared function in ShareContext and UploadScreen - Move os import to top of test file - Update test docstring to reflect new behavior Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
21 lines
567 B
TypeScript
21 lines
567 B
TypeScript
/**
|
|
* Normalise a file URI for deduplication.
|
|
*
|
|
* - Decode percent-encoding (`%20` → ` `)
|
|
* - Collapse consecutive slashes after the scheme (`file:////` → `file:///`)
|
|
* - Strip trailing slashes
|
|
*/
|
|
export function normalizeFileUri(uri: string): string {
|
|
let norm: string;
|
|
try {
|
|
norm = decodeURIComponent(uri);
|
|
} catch {
|
|
norm = uri;
|
|
}
|
|
// Collapse multiple slashes after the scheme (e.g. file://// → file:///)
|
|
norm = norm.replace(/^(file:\/\/)\/{2,}/, "$1/");
|
|
// Strip trailing slash
|
|
norm = norm.replace(/\/+$/, "");
|
|
return norm;
|
|
}
|