Copilot commented on code in PR #3142:
URL: https://github.com/apache/tika/pull/3142#discussion_r3955785334
##########
tika-core/src/main/java/org/apache/tika/io/FilenameUtils.java:
##########
@@ -400,7 +400,7 @@ public static String calculateExtension(Metadata metadata,
String defaultValue)
if (ext != null) {
return ext;
}
- return ".bin";
+ return defaultValue;
}
Review Comment:
`calculateExtension`’s Javadoc states the returned extension includes the
initial ".", and callers like `getSanitizedEmbeddedFileName/Path` concatenate
`namePart + extension`. After changing the fallback to `return defaultValue`,
this method can now return a value without a leading dot if callers pass e.g.
"pdf", which breaks the documented contract and can produce filenames like
`namepdf`.
Consider normalizing `defaultValue` to ensure it starts with "." (when
non-blank), or update the Javadoc to explicitly require callers to include the
dot.
##########
tika-core/src/test/java/org/apache/tika/io/FilenameUtilsTest.java:
##########
@@ -245,6 +245,11 @@ public void testEmbeddedFilePaths() throws Exception {
}
+ @Test
+ public void testCalculateExtensionUnknownValue() {
+ assertEquals(".pdf", FilenameUtils.calculateExtension(getMetadata("the
quick brown fox", "unknown"), ".pdf"));
+ }
Review Comment:
This test uses `HttpHeaders.CONTENT_TYPE = "unknown"`, which is not a valid
MIME type and primarily exercises the exception/parse-failure path. To better
match the intent of “unknown (but syntactically valid) value”, consider using a
well-formed but unregistered type (e.g., `application/x-tika-unknown`) so the
test more clearly targets the unknown-mime behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]