react-native-img-cache icon indicating copy to clipboard operation
react-native-img-cache copied to clipboard

Remove colons from the file extension when caching an image.

Open henrytndrly opened this issue 7 years ago • 3 comments

iOS doesn’t like having colons in filenames, and Twitter uses colons to identify the size of an image after the filename, e.g. ‘https://pbs.twimg.com/media/foo.jpg:large’, and this library was using the colon in the extension which resulted in images not displaying. The solution was to replace the colons in the extension. (Issue came to light due to using OpenGraph lookups to get appropriate images for embedded tweets)

henrytndrly avatar Jul 19 '17 12:07 henrytndrly

Thank for doing this!

What do you mean by iOS doesn't like colons in filenames? Is there a specification of the supported filenames? It would be good then to support all of them in this PR.

wcandillon avatar Jul 19 '17 14:07 wcandillon

TL;DR: It's only colons that need to be processed...

--

The initial guidance I saw was this SO post: https://stackoverflow.com/questions/4924898/how-to-preserve-colon-character-in-filename-when-using-nsdata-method-writetofil so I just tried to replace the colon character, and the image started showing.

A bit more googling suggests that it is 'just' colons that are not liked (beyond slashes, but they're already treated as a directory separator...) https://discussions.apple.com/thread/949275?tstart=0 http://xahlee.info/mswin/allowed_chars_in_file_names.html

Also found this google result which I think is the 'most' authoritative... https://books.google.co.uk/books?id=62xkJo6JXwAC&pg=PA616&lpg=PA616&dq=darwin+allowed+characters+in+file+names&source=bl&ots=PBQiurDAwK&sig=NE_nieRW_2iaZ3UyrfWsaSZ49wc&hl=en&sa=X&ved=0ahUKEwir2dLvyJXVAhXJB8AKHZmdBRgQ6AEITjAF#v=onepage&q=darwin%20allowed%20characters%20in%20file%20names&f=false The first sentence of the 'File Paths' paragraph: "The Mac filesystem, HFS+, allows any characters except colons in filenames." [...because they are treated as delimiters...]

I've not yet found any Apple sourced specification on allowed characters.

henrytndrly avatar Jul 19 '17 14:07 henrytndrly

(Also: my app is just focussing on iOS at the moment, however I think the code should also work on Android, as that probably doesn't care in the first place, and we're just operating on an 'internal' identifier)

henrytndrly avatar Jul 19 '17 15:07 henrytndrly