DecodedFile::decode falls back to FileType::text_file for anything it does not
recognise, and translate_html is true for it. So a caller that asks the core what a
file is, and trusts the answer, ends up showing a page of nonsense instead of saying
the file cannot be opened.
Measured with 6.10.1 (the Apple xcframework), passing each file through decode,
html::translate and the http server:
| file |
file_type |
as_text_file().charset() |
translate |
GET page |
64 random bytes, named .odt |
text_file |
null |
ok |
200, 27 KB |
| a sqlite database |
text_file |
null |
ok |
200, 27 KB |
| an empty file |
text_file |
null |
ok |
200, 27 KB |
| a real text file |
text_file |
UTF-8 |
ok |
200, 27 KB |
Nothing throws and nothing in the answer distinguishes the first three from the last,
except the charset.
Both readers work around it the same way, by asking for the charset themselves and
treating a null as unsupported — OpenDocument.droid in CoreLoader.kt:
if (file.isTextFile && file.asTextFile().charset() == null) {
throw OdrException.UnsupportedFileType("no charset could be detected: $inputPath")
}
OpenDocument.ios has just copied that check. It would be better made once, here.
Proposal: do not report a file as text when no charset can be detected. Either
decode fails and list_file_types leaves text_file out, or open/translate
throws for it. Whichever fits the design — the point is that the core's own answer
should say the file is not readable, rather than every caller re-deriving it from the
charset.
One note against the charset alone as the rule: an empty file also has no charset, and
"empty text file" may be worth treating as text rather than as unreadable.
DecodedFile::decodefalls back toFileType::text_filefor anything it does notrecognise, and
translate_htmlis true for it. So a caller that asks the core what afile is, and trusts the answer, ends up showing a page of nonsense instead of saying
the file cannot be opened.
Measured with 6.10.1 (the Apple xcframework), passing each file through
decode,html::translateand the http server:file_typeas_text_file().charset().odttext_filetext_filetext_filetext_fileUTF-8Nothing throws and nothing in the answer distinguishes the first three from the last,
except the charset.
Both readers work around it the same way, by asking for the charset themselves and
treating a null as unsupported — OpenDocument.droid in
CoreLoader.kt:OpenDocument.ios has just copied that check. It would be better made once, here.
Proposal: do not report a file as text when no charset can be detected. Either
decodefails andlist_file_typesleavestext_fileout, oropen/translatethrows for it. Whichever fits the design — the point is that the core's own answer
should say the file is not readable, rather than every caller re-deriving it from the
charset.
One note against the charset alone as the rule: an empty file also has no charset, and
"empty text file" may be worth treating as text rather than as unreadable.