fix(media): parse local file extensions across path styles (#105614)

* fix(media): parse local file extensions across path styles

* docs: note cross-platform media path fix

* docs: keep release notes in PR context

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
xiaobao-k8s
2026-07-13 08:35:43 +08:00
committed by GitHub
parent 5429f06940
commit ff166425d1
2 changed files with 4 additions and 1 deletions
+2
View File
@@ -209,6 +209,8 @@ describe("getFileExtension", () => {
{ filePath: "https://cdn.example.com/bad%ZZ%2Emp4", expected: undefined },
{ filePath: "https://cdn.example.com/render%2Emp4/", expected: undefined },
{ filePath: String.raw`C:\media\clip.MP4`, expected: ".mp4" },
{ filePath: String.raw`C:\media.folder\clip`, expected: undefined },
{ filePath: String.raw`C:\media.folder\clip.MP4`, expected: ".mp4" },
] as const)("extracts $expected from $filePath", ({ filePath, expected }) => {
expect(getFileExtension(filePath)).toBe(expected);
});
+2 -1
View File
@@ -1,6 +1,7 @@
// Media Core module implements mime behavior.
import path from "node:path";
import { type MediaKind, mediaKindFromMime } from "./constants.js";
import { extnameFromAnyPath } from "./file-name.js";
import { createLazyImportLoader } from "./lazy-import.js";
/** Maximum byte prefix passed to dependency MIME sniffers for bounded memory/CPU work. */
@@ -157,7 +158,7 @@ export function getFileExtension(filePath?: string | null): string | undefined {
} catch {
// fall back to plain path parsing
}
const ext = path.extname(filePath).toLowerCase();
const ext = extnameFromAnyPath(filePath).toLowerCase();
return ext || undefined;
}