-
-
Notifications
You must be signed in to change notification settings - Fork 679
iOS: Fix image display issue in Lightbox. #2246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hello @gokcan, it seems like you have referenced an issue in your pull request, but you have not referenced that issue in your commit message(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged. Please run An example of a correctly-formatted commit: Thank you for your contributions to Zulip! |
f3d441a to
e2b5ccf
Compare
src/utils/url.js
Outdated
| export const encodeImageUri = (uri: string): string => { | ||
| const last = uri.lastIndexOf('/'); | ||
| const imageName = uri.substring(last + 1); | ||
| const original = uri.substring(0, last); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is original a good name to represent that part of the string?
Is it maybe path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, path sounds good. :)
| }` | ||
| : ''; | ||
|
|
||
| export const encodeImageUri = (uri: string): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a test for this function will prove that it works correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the tests now. Thank you.
4d2029f to
dbdf1ac
Compare
|
Thanks @gokcan for digging into this! This solution looks brittle to me -- I worry that there may still be a bug in this path, and also that we're at high risk of creating another bug like this here later. I think with a little more work, we can make a good solid solution that makes this code much more likely to stay robust. The key thing I'd like to see in a fix is that when looking at a piece of this code, for example I think the root cause of this bug is basically that we weren't clear on the answers to those questions, and so the answers ended up not matching up between different parts of the code. And looking at this version, I'm not quite sure what the answers are either. One great way to resolve this would be for the answers to all the questions like this to be "it's a valid URL which you can load the image from." It seems like that's not yet the case for the |
|
Hi @gnprice, Actually, we are able to display those images with special characters in
Also, we don't have any issues on Android side, right? This is because that RN library(photo-view) uses different native libraries for different platforms (obviously). Specifically, the iOS part relies on MWPhotoBrowser. What I found is: The RN library(photo-view) uses NSURL without encoding the NSString to UTF-8. (Solution to this in 3rd bullet point below ↓). After that, I dug deeper.. and found that the core logic of MWPhotoBrowser for async download operation, uses another library called SDWebImage. Not surprisingly, there are open issues also about this problem on their repos 1 2. In the end, we have 3 options:
On the other hand,
and after, like this: I choose to use
Looking forward for your suggestions on this @gnprice! |
|
Thanks for this investigation! These resources are helpful. One bit of terminology: looking at RFC 3986, which is the main RFC describing URIs (*) or URLs, we find that
and in particular that every character in a proper URI is a character from ASCII. There is no such thing as a URI nor a URL, according to the official definitions, that contains non-ASCII characters. I've added a comment on the PR you opened in react-native-photo-view. Perhaps that will get fixed there, and in that case it's no longer a live problem for us. More thoughts coming in another comment. (*) And although the RFCs say "URI", I usually prefer to say "URL" because the distinction is basically dead -- even in the formal terminology of the RFCs, virtually every URI that anyone cares about is in fact a URL -- and "URL" is better understood. PS - the URLs we're talking about are not in fact URNs. :-) Few URLs, or URIs, are. Fortunately, as RFC 3986 says, you can basically ignore the concept of a URN, and I recommend doing so. |
|
So, whether the issue gets fixed in react-native-photo-view or not, I'd still like to sort out having clear answers to what type of thing each prop or parameter in our code, like
Given how broadly this either/or semantics is present in RN, I'm OK with the answer to "what is this supposed to be" being "a React Native Then it's just a matter of converting that to what So here's the logic I propose:
Want to try doing that? |
527db80 to
701fa85
Compare
|
Thanks @gokcan ! Quick workflow bits:
Inside this code:
Would you try that approach? (BTW, I appreciate these tests!) |
Users may upload images from their local storage or (externally). Those images may have Non-ASCII characters in filename. iOS app of Zulip could not be able to display those images correctly. To resolve this issue, we can encode the 'file-dependent' part of the image url to UTF-8. Fixes zulip#2113
If the image uri does not contain any non-ASCII characters, there is no need to percent-encode it. Also, call ``encodeImageUri()` just before giving the image uri as a 'source' attribute of `PhotoView`.
|
A note, as I close a tab I had open: The function |
|
@gnprice I think it mostly does what we want. However, it does not take into account the 'double-encoding' case. We can use the |
|
Heads up @gokcan, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
|
Closing this PR as it's gone stale. Thanks @gokcan for your work on it! |
iOS app could not be able to display images having non-ASCII characters
(e.g. 你好世界, алуй, مرحبا) in their filenames.
This PR fixes #2113.