[
https://issues.apache.org/jira/browse/TIKA-4882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18112576#comment-18112576
]
ASF GitHub Bot commented on TIKA-4882:
--------------------------------------
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.
> FilenameUtils.calculateExtension ignores defaultValue on unknown path
> ---------------------------------------------------------------------
>
> Key: TIKA-4882
> URL: https://issues.apache.org/jira/browse/TIKA-4882
> Project: Tika
> Issue Type: Bug
> Components: core
> Reporter: Tim Grein
> Priority: Minor
>
> FilenameUtils.calculateExtension ignores an unknown extension in the sense
> that the behavior on an unknown extension is not specified in the javadoc and
> it's not explicitly handled. It should probably be either handled or
> explicitly documented.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)