Skip to content

Commit 65ed0a7

Browse files
author
Julia Boes
committedSep 21, 2021
8273655: content-types.properties files are missing some common types
Reviewed-by: bpb, dfuchs
1 parent c60bcd0 commit 65ed0a7

File tree

3 files changed

+214
-34
lines changed

3 files changed

+214
-34
lines changed
 

‎src/java.base/unix/classes/sun/net/www/content-types.properties

+86-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ temp.file.template: /tmp/%s
2727
#
2828
application/octet-stream: \
2929
description=Generic Binary Stream;\
30-
file_extensions=.saveme,.dump,.hqx,.arc,.o,.a,.bin,.exe,.z,.gz
30+
file_extensions=.saveme,.dump,.hqx,.arc,.o,.a,.bin,.exe,.z
3131

3232
application/oda: \
3333
description=ODA Document;\
@@ -253,14 +253,26 @@ image/bmp: \
253253
description=Bitmap Image;\
254254
file_extensions=.bmp;
255255

256+
image/webp: \
257+
description=WEBP image;\
258+
file_extensions=.webp;
259+
260+
text/css: \
261+
description=CSS File;\
262+
file_extensions=.css;
263+
256264
text/html: \
257265
description=HTML Document;\
258266
file_extensions=.htm,.html;\
259267
icon=html
260268

269+
text/javascript: \
270+
description=JavaScript File;\
271+
file_extensions=.js;
272+
261273
text/plain: \
262274
description=Plain Text;\
263-
file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el;\
275+
file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el,.php,.adoc,.py;\
264276
icon=text;\
265277
action=browser
266278

@@ -272,6 +284,14 @@ text/x-setext: \
272284
description=Structure Enhanced Text;\
273285
file_extensions=.etx
274286

287+
text/csv: \
288+
description=CSV File;\
289+
file_extensions=.csv;
290+
291+
text/markdown: \
292+
description=Markdown File;\
293+
file_extensions=.md,.markdown
294+
275295
video/mp4: \
276296
description=MPEG-4 Video;\
277297
file_extensions=.m4v,.mp4
@@ -311,3 +331,67 @@ message/rfc822: \
311331
application/xml: \
312332
description=XML document;\
313333
file_extensions=.xml
334+
335+
application/rtf: \
336+
description=WordPad Document;\
337+
file_extensions=.rtf;
338+
339+
application/gzip: \
340+
description=GZip File;\
341+
file_extensions=.gz;
342+
343+
application/vnd.oasis.opendocument.presentation: \
344+
description=OpenDocument presentation document;\
345+
file_extensions=.odp;
346+
347+
application/vnd.oasis.opendocument.spreadsheet: \
348+
description=OpenDocument spreadsheet document;\
349+
file_extensions=.ods;
350+
351+
application/vnd.oasis.opendocument.text: \
352+
description=OpenDocument text document;\
353+
file_extensions=.odt;
354+
355+
application/vnd.ms-excel: \
356+
description=Microsoft Excel File;\
357+
file_extensions=.xls;
358+
359+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: \
360+
description=XLSX File;\
361+
file_extensions=.xlsx;
362+
363+
application/vnd.openxmlformats-officedocument.presentationml.presentation: \
364+
description=PPTX File;\
365+
file_extensions=.pptx;
366+
367+
application/vnd.ms-powerpoint: \
368+
description=Microsoft PowerPoint File;\
369+
file_extensions=.ppt;
370+
371+
application/x-7z-compressed: \
372+
description=7-Zip File;\
373+
file_extensions=.7z;
374+
375+
application/msword: \
376+
description=Microsoft Word File;\
377+
file_extensions=.doc;
378+
379+
application/vnd.openxmlformats-officedocument.wordprocessingml.document: \
380+
description=DOCX File;\
381+
file_extensions=.docx;
382+
383+
application/vnd.rar: \
384+
description=RAR File;\
385+
file_extensions=.rar;
386+
387+
application/json: \
388+
description=JSON File;\
389+
file_extensions=.json;
390+
391+
application/bz2: \
392+
description=BZ2 File;\
393+
file_extensions=.bz2;
394+
395+
application/java-archive: \
396+
description=JAR File;\
397+
file_extensions=.jar;

‎src/java.base/windows/classes/sun/net/www/content-types.properties

+83-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ temp.file.template: c:\\temp\\%s
2727
#
2828
application/octet-stream: \
2929
description=Generic Binary Stream;\
30-
file_extensions=.saveme,.dump,.hqx,.arc,.obj,.lib,.bin,.exe,.zip,.gz
30+
file_extensions=.saveme,.dump,.hqx,.arc,.obj,.lib,.bin,.exe
3131

3232
application/oda: \
3333
description=ODA Document;\
@@ -43,11 +43,15 @@ application/postscript: \
4343
icon=ps
4444

4545
application/rtf: \
46-
description=Wordpad Document;\
46+
description=WordPad Document;\
4747
file_extensions=.rtf;\
4848
action=application;\
4949
application=wordpad.exe %s
5050

51+
application/gzip: \
52+
description=GZip File;\
53+
file_extensions=.gz;
54+
5155
application/x-dvi: \
5256
description=TeX DVI File;\
5357
file_extensions=.dvi
@@ -250,14 +254,26 @@ image/bmp: \
250254
description=Bitmap Image;\
251255
file_extensions=.bmp;
252256

257+
image/webp: \
258+
description=WEBP image;\
259+
file_extensions=.webp;
260+
261+
text/css: \
262+
description=CSS File;\
263+
file_extensions=.css;
264+
253265
text/html: \
254266
description=HTML Document;\
255267
file_extensions=.htm,.html;\
256268
icon=html
257269

270+
text/javascript: \
271+
description=JavaScript File;\
272+
file_extensions=.js;
273+
258274
text/plain: \
259275
description=Plain Text;\
260-
file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el;\
276+
file_extensions=.text,.c,.cc,.c++,.h,.pl,.txt,.java,.el,.php,.adoc,.py;\
261277
icon=text;\
262278
action=browser
263279

@@ -269,6 +285,14 @@ text/x-setext: \
269285
description=Structure Enhanced Text;\
270286
file_extensions=.etx
271287

288+
text/csv: \
289+
description=CSV File;\
290+
file_extensions=.csv;
291+
292+
text/markdown: \
293+
description=Markdown File;\
294+
file_extensions=.md,.markdown
295+
272296
video/mp4: \
273297
description=MPEG-4 Video;\
274298
file_extensions=.m4v,.mp4
@@ -308,3 +332,59 @@ message/rfc822: \
308332
application/xml: \
309333
description=XML document;\
310334
file_extensions=.xml
335+
336+
application/vnd.oasis.opendocument.presentation: \
337+
description=OpenDocument presentation document;\
338+
file_extensions=.odp;
339+
340+
application/vnd.oasis.opendocument.spreadsheet: \
341+
description=OpenDocument spreadsheet document;\
342+
file_extensions=.ods;
343+
344+
application/vnd.oasis.opendocument.text: \
345+
description=OpenDocument text document;\
346+
file_extensions=.odt;
347+
348+
application/vnd.ms-excel: \
349+
description=Microsoft Excel File;\
350+
file_extensions=.xls;
351+
352+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: \
353+
description=XLSX File;\
354+
file_extensions=.xlsx;
355+
356+
application/vnd.openxmlformats-officedocument.presentationml.presentation: \
357+
description=PPTX File;\
358+
file_extensions=.pptx;
359+
360+
application/vnd.ms-powerpoint: \
361+
description=Microsoft PowerPoint File;\
362+
file_extensions=.ppt;
363+
364+
application/x-7z-compressed: \
365+
description=7-Zip File;\
366+
file_extensions=.7z;
367+
368+
application/msword: \
369+
description=Microsoft Word File;\
370+
file_extensions=.doc;
371+
372+
application/vnd.openxmlformats-officedocument.wordprocessingml.document: \
373+
description=DOCX File;\
374+
file_extensions=.docx;
375+
376+
application/vnd.rar: \
377+
description=RAR File;\
378+
file_extensions=.rar;
379+
380+
application/json: \
381+
description=JSON File;\
382+
file_extensions=.json;
383+
384+
application/bz2: \
385+
description=BZ2 File;\
386+
file_extensions=.bz2;
387+
388+
application/java-archive: \
389+
description=JAR File;\
390+
file_extensions=.jar;

‎test/jdk/java/nio/file/Files/probeContentType/Basic.java

+45-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/* @test
25-
* @bug 4313887 8129632 8129633 8162624 8146215 8162745
25+
* @bug 4313887 8129632 8129633 8162624 8146215 8162745 8273655
2626
* @summary Unit test for probeContentType method
2727
* @library ../..
2828
* @build Basic SimpleFileTypeDetector
@@ -31,6 +31,7 @@
3131

3232
import java.io.*;
3333
import java.nio.file.*;
34+
import java.util.List;
3435
import java.util.stream.Stream;
3536

3637
/**
@@ -95,26 +96,22 @@ private static int checkContentTypes(String expected, String actual) {
9596
return 0;
9697
}
9798

98-
static int checkContentTypes(String[] extensions, String[] expectedTypes)
99+
static int checkContentTypes(ExType[] exTypes)
99100
throws IOException {
100-
if (extensions.length != expectedTypes.length) {
101-
System.err.println("Parameter array lengths differ");
102-
return 1;
103-
}
104-
105101
int failures = 0;
106-
for (int i = 0; i < extensions.length; i++) {
107-
String extension = extensions[i];
102+
for (int i = 0; i < exTypes.length; i++) {
103+
String extension = exTypes[i].extension();
104+
List<String> expectedTypes = exTypes[i].expectedTypes();
108105
Path file = Files.createTempFile("foo", "." + extension);
109106
try {
110107
String type = Files.probeContentType(file);
111108
if (type == null) {
112109
System.err.println("Content type of " + extension
113110
+ " cannot be determined");
114111
failures++;
115-
} else if (!type.equals(expectedTypes[i])) {
112+
} else if (!expectedTypes.contains(type)) {
116113
System.err.printf("Content type: %s; expected: %s%n",
117-
type, expectedTypes[i]);
114+
type, expectedTypes);
118115
failures++;
119116
}
120117
} finally {
@@ -155,27 +152,46 @@ public static void main(String[] args) throws IOException {
155152
Files.delete(file);
156153
}
157154

158-
// Verify that certain media extensions are mapped to the correct type.
159-
String[] extensions = new String[]{
160-
"jpg",
161-
"mp3",
162-
"mp4",
163-
"pdf",
164-
"png",
165-
"webm"
155+
// Verify that certain extensions are mapped to the correct type.
156+
var exTypes = new ExType[] {
157+
new ExType("adoc", List.of("text/plain")),
158+
new ExType("bz2", List.of("application/bz2", "application/x-bzip2")),
159+
new ExType("css", List.of("text/css")),
160+
new ExType("csv", List.of("text/csv")),
161+
new ExType("doc", List.of("application/msword")),
162+
new ExType("docx", List.of("application/vnd.openxmlformats-officedocument.wordprocessingml.document")),
163+
new ExType("gz", List.of("application/gzip", "application/x-gzip")),
164+
new ExType("jar", List.of("application/java-archive", "application/x-java-archive")),
165+
new ExType("jpg", List.of("image/jpeg")),
166+
new ExType("js", List.of("text/javascript", "application/javascript")),
167+
new ExType("json", List.of("application/json")),
168+
new ExType("markdown", List.of("text/markdown")),
169+
new ExType("md", List.of("text/markdown")),
170+
new ExType("mp3", List.of("audio/mpeg")),
171+
new ExType("mp4", List.of("video/mp4")),
172+
new ExType("odp", List.of("application/vnd.oasis.opendocument.presentation")),
173+
new ExType("ods", List.of("application/vnd.oasis.opendocument.spreadsheet")),
174+
new ExType("odt", List.of("application/vnd.oasis.opendocument.text")),
175+
new ExType("pdf", List.of("application/pdf")),
176+
new ExType("php", List.of("text/plain", "text/php")),
177+
new ExType("png", List.of("image/png")),
178+
new ExType("ppt", List.of("application/vnd.ms-powerpoint")),
179+
new ExType("pptx",List.of("application/vnd.openxmlformats-officedocument.presentationml.presentation")),
180+
new ExType("py", List.of("text/plain", "text/x-python-script")),
181+
new ExType("rar", List.of("application/vnd.rar")),
182+
new ExType("rtf", List.of("application/rtf", "text/rtf")),
183+
new ExType("webm", List.of("video/webm")),
184+
new ExType("webp", List.of("image/webp")),
185+
new ExType("xls", List.of("application/vnd.ms-excel")),
186+
new ExType("xlsx", List.of("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")),
187+
new ExType("7z", List.of("application/x-7z-compressed")),
166188
};
167-
String[] expectedTypes = new String[] {
168-
"image/jpeg",
169-
"audio/mpeg",
170-
"video/mp4",
171-
"application/pdf",
172-
"image/png",
173-
"video/webm"
174-
};
175-
failures += checkContentTypes(extensions, expectedTypes);
189+
failures += checkContentTypes(exTypes);
176190

177191
if (failures > 0) {
178192
throw new RuntimeException("Test failed!");
179193
}
180194
}
195+
196+
record ExType(String extension, List<String> expectedTypes) { }
181197
}

0 commit comments

Comments
 (0)
Please sign in to comment.