Skip to content

Commit 9b6deeb

Browse files
committed
fix: support Windows paths in whiteout handlers
Refactor isWhitedOutFile to use cross-platform path.basename and update removeWhiteoutPrefix regex to support both POSIX and Windows path separators. This resolves a regression introduced by the initial whiteout regex fix where Windows-style paths would not be correctly identified or parsed.
1 parent f46d29b commit 9b6deeb

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/extractor/index.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,26 +266,17 @@ function layersWithLatestFileModifications(
266266
* https://www.madebymikal.com/interpreting-whiteout-files-in-docker-image-layers
267267
* https://github.com/opencontainers/image-spec/blob/main/layer.md#whiteouts
268268
*/
269-
export function isWhitedOutFile(filename: string) {
270-
const lastSlashIndex = filename.lastIndexOf("/");
271-
272-
if (lastSlashIndex === -1) {
273-
// it's a file name, not a path
274-
return filename.startsWith(".wh.");
275-
} else {
276-
// it's a path, so check the last part
277-
const filenameToCheck = filename.substring(lastSlashIndex + 1);
278-
return filenameToCheck.startsWith(".wh.");
279-
}
269+
export function isWhitedOutFile(filename: string): boolean {
270+
return path.basename(filename).startsWith(".wh.");
280271
}
281272

282273
/**
283274
* Remove the .wh. prefix from a whiteout file to get the original filename
284275
*/
285276
export function removeWhiteoutPrefix(filename: string): string {
286-
// Replace .wh. that appears at the start or after the last slash,
287-
// and ensure no slashes come after .wh.
288-
return filename.replace(/^(.*\/)?\.wh\.([^\/]*)$/, "$1$2");
277+
// Replace .wh. that appears at the start or after the last slash/backslash,
278+
// and ensure no slashes/backends come after .wh.
279+
return filename.replace(/^(.*[\/\\])?\.wh\.([^\/\\]*)$/, "$1$2");
289280
}
290281

291282
function isBufferType(type: FileContent): type is Buffer {

0 commit comments

Comments
 (0)