Skip to content

Commit 296be8f

Browse files
committed
Reject blank metadata values
validate --entry values in write-metadata and return code 2 when the value is blank to prevent invalid metadata writes. also print stream and tag data in a stable structured format with counts, indexed streams, and sorted tag keys for predictable output.
1 parent 89ca871 commit 296be8f

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>me.tamkungz.codecmedia</groupId>
99
<artifactId>codecmedia-cli</artifactId>
10-
<version>1.1.1</version>
10+
<version>1.1.2</version>
1111
<packaging>jar</packaging>
1212

1313
<name>CodecMedia CLI</name>

src/main/java/me/tamkungz/codecmedia/CodecMediaCli.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ private static int handleWriteMetadata(CodecMediaEngine engine, String[] args, P
412412
if (key.isBlank()) {
413413
throw new IllegalArgumentException("Entry key must not be blank");
414414
}
415+
if (value.isBlank()) {
416+
throw new IllegalArgumentException("Entry value must not be blank");
417+
}
415418
entries.put(key, value);
416419
}
417420

@@ -439,8 +442,22 @@ private static void printProbe(PrintStream out, ProbeResult result) {
439442
out.println("extension=" + result.extension());
440443
out.println("mediaType=" + result.mediaType());
441444
out.println("durationMillis=" + result.durationMillis());
442-
out.println("streams=" + result.streams());
443-
out.println("tags=" + result.tags());
445+
446+
var streams = result.streams();
447+
out.println("streams.count=" + streams.size());
448+
for (int i = 0; i < streams.size(); i++) {
449+
out.println("streams[" + i + "]=" + streams.get(i));
450+
}
451+
452+
var tags = result.tags();
453+
if (tags == null || tags.isEmpty()) {
454+
out.println("tags.count=0");
455+
} else {
456+
out.println("tags.count=" + tags.size());
457+
tags.entrySet().stream()
458+
.sorted(Map.Entry.comparingByKey())
459+
.forEach(entry -> out.println("tags." + entry.getKey() + "=" + entry.getValue()));
460+
}
444461
}
445462

446463
/**

src/test/java/me/tamkungz/codecmedia/CodecMediaCliTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ void shouldReturnCode2WhenWriteMetadataEntryValueMissing() {
7676
assertTrue(result.err().contains("Usage: write-metadata"));
7777
}
7878

79+
@Test
80+
void shouldReturnCode2WhenWriteMetadataEntryValueBlank() {
81+
RunResult result = runCli(new String[] {"write-metadata", "in.mp3", "--entry", "artist= "});
82+
83+
assertEquals(2, result.code());
84+
assertTrue(result.err().contains("Entry value must not be blank"));
85+
}
86+
7987
@Test
8088
void shouldReturnCode2WhenPlayHasUnknownOption() {
8189
RunResult result = runCli(new String[] {"play", "song.mp3", "--nope"});

0 commit comments

Comments
 (0)