Skip to content
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

UTF-8 symbols and spaces in image URL #31

Closed
nostra13 opened this issue May 30, 2012 · 7 comments
Closed

UTF-8 symbols and spaces in image URL #31

nostra13 opened this issue May 30, 2012 · 7 comments

Comments

@nostra13
Copy link
Owner

Image can't be loaded if image URL contains UTF-8 locale-specific symbols (e.g. 'ф', 'à', 'ß')

@yevon
Copy link

yevon commented Jul 24, 2012

The same if it contains spaces!

It seems that it can be solved by using urlEncoder.

May be this helps
http:https://stackoverflow.com/questions/1828641/how-to-parse-a-uri-like-this-in-java

@nostra13
Copy link
Owner Author

I tried to found nice solution for this bug but couldn't do it. UrlEncoder didn't help me.

@yevon
Copy link

yevon commented Jul 27, 2012

I have also seen this:
http:https://stackoverflow.com/questions/3286067/url-encoding-in-android

String urlStr = "http:https://abc.dev.domain.com/0007AC/ads/800x480 15sec h.264.mp4";
URL url = new URL(urlStr);
URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
url = uri.toURL();

I haven't tried it, i will try when I have time

@crush3r
Copy link

crush3r commented Aug 7, 2012

yevons code works fine. Please, add this to jar library.

@nostra13
Copy link
Owner Author

nostra13 commented Aug 7, 2012

May be it fixes problem for spaces, but it doesn't fix "UTF-8 symbols problem".

@crush3r
Copy link

crush3r commented Aug 7, 2012

It also fixes a problem with '[' ']'

@yevon
Copy link

yevon commented Aug 8, 2012

I have made some tests, and I don't know the reason of using Uri in all the code. For knowing the procol isn't enough with String.startsWith("/") -> file , String.startsWith("http") , String.startsWith("content") etc? Without using Uri, all this problems dissappear.

Something like that:

private InputStream getInputStream(String url) {
InputStream stream = null;
URL internetUrl;

    if (url.startsWith(PROTOCOL_FILE)) {
        try {
            stream = new FileInputStream(url);
        } catch (FileNotFoundException e) {
        }
    } else if (url.startsWith(PROTOCOL_CONTENT)) {
        try {
            stream = resolver.openInputStream(Uri.parse(url));
        } catch (FileNotFoundException e) {
        }
    } else if (url.startsWith(PROTOCOL_HTTP) || url.startsWith(PROTOCOL_HTTPS) || url.startsWith(PROTOCOL_FTP)) {
        try {
            internetUrl = new URL(url);
            stream = internetUrl.openStream();
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return stream;

}

nostra13 added a commit that referenced this issue Aug 28, 2012
Issue #31 - UTF-8 symbols and spaces in image URL
tuolin2013 pushed a commit to tuolin2013/universal_image_loader_lib that referenced this issue Nov 20, 2013
Fixed issue with UTF-8 symbols and spaces in image URL as described in
this thread:
nostra13/Android-Universal-Image-Loader#31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants