WW sometimes puts binary file contents in the output page
Status: Beta
Brought to you by:
worden
It wants you to register the file extensions you'll use and use them correctly. It could do mime type detection (but I'm worried this would produce annoying false positives and negatives). It could at least check things for binary content just before it displays them as source.
Anonymous
The Unix
fileanddiffutilities check for binary content by reading the first 1000 bytes and seeing if they include any'\0'characters. WW could definitely do that.I think this only need to prevent displaying binary stuff as source, so I can do a binary-content check at the last minute before source display, in
display_file_contents. At that point, it's already got the file contents loaded into a variable, so it should be straightforward to check the first 1000 bytes. I wonder, though, if I should check it for unicode-ness, rather than looking for '\0', since anything that's not unicode is likely to be a problem.Done, seems to work okay.
The side effect of this is that binary file types such as mp4, etc. no longer need to be listed in $wwLinkExtensions - this might have side effects such as causing it to try to upload such files to text wiki pages. I want to check on that before closing this ticket.
Well, maybe we do want to keep them in $wwLinkExtensions though, because if not, when a file's oversize (as video files often are), it doesn't load them into memory and so doesn't do the unicode check. Instead you get the "file is too large to display" message. It's avoided by using display=link or listing the file's extension in $wwLinkExtensions.
Given that, I don't feel too urgent about the uploading of binary files issue. I've opened [#548] for that.
Related
Bugs: #548