RFR: 8287237: (fs) Files.probeContentType returns null if filename contains hash mark on Linux [v2]
Brian Burkhalter
bpb at openjdk.java.net
Tue May 31 18:13:36 UTC 2022
On Tue, 31 May 2022 16:41:57 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> src/java.base/share/classes/sun/net/www/MimeTable.java line 188:
>>
>>> 186: int hashIndex = fname.lastIndexOf(HASH_MARK);
>>> 187: if (hashIndex > 0) {
>>> 188: String ext = getFileExtension(fname.substring(0, hashIndex - 1));
>>
>> Hello Brian, I think there's a bug here. Not introduced by this PR but even in the current master. I think that `fname.substring(0, hashIndex -1)` call should actually be `fname.substring(0, hashIndex)`. For example, in its current form, if `fname` is `a.png#foo` then `fname.substring(...)` here will return `a.pn` instead of `a.png`. It looks like we don't have a test for that case.
>
> I agree. I saw that myself. As nothing seems broken I did not want to touch it but I will investigate.
This was probably never caught because all our Linux machines seem to have `/etc/mime.types`.
Fixed by 7c877f9ee2a0788849bac4d64a4ab4c89cbc9e0c.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8909
More information about the net-dev
mailing list