Skip to content

Commit 76a3a72

Browse files
committed
fix(dockerfile): use case-insensitive scratch comparison
Change "scratch".equals(image) to "scratch".equalsIgnoreCase(image) so FROM SCRATCH, FROM Scratch, and other case variants are properly skipped during Dockerfile parsing, matching the case-insensitive handling of the FROM keyword itself. Fixes: TC-5098 Assisted-by: Claude Code
1 parent 3b43c23 commit 76a3a72

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/main/java/io/github/guacsec/trustifyda/providers/DockerfileProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static List<String> parseAllFromImages(Path dockerfile) throws IOException {
137137
continue;
138138
}
139139
}
140-
if ("scratch".equals(image)) {
140+
if ("scratch".equalsIgnoreCase(image)) {
141141
LOG.info(String.format("Skipping FROM scratch in %s", dockerfile));
142142
continue;
143143
}

src/test/java/io/github/guacsec/trustifyda/providers/Dockerfile_Provider_Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ void skips_scratch_and_returns_remaining_images() throws IOException {
217217
assertThat(images).doesNotContain("scratch");
218218
}
219219

220+
/** Verifies that FROM SCRATCH (uppercase) is skipped case-insensitively. */
221+
@Test
222+
void skips_scratch_case_insensitively() throws IOException {
223+
var dockerfile = TEST_MANIFESTS.resolve("scratch_uppercase/Dockerfile");
224+
225+
List<String> images = DockerfileProvider.parseAllFromImages(dockerfile);
226+
227+
assertThat(images).hasSize(1).containsExactly("node:18");
228+
assertThat(images).doesNotContain("SCRATCH");
229+
}
230+
220231
/** Verifies that a Dockerfile with no analyzable FROM instructions throws IOException. */
221232
@Test
222233
void throws_when_no_analyzable_from_instruction() {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:18 AS builder
2+
3+
WORKDIR /app
4+
RUN npm ci
5+
6+
FROM SCRATCH
7+
8+
COPY --from=builder /app/dist /

0 commit comments

Comments
 (0)