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

FIX: Correctly escape parameters in URL. #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jstastny
Copy link
Contributor

Before this, the words containing non-ascii characters (for example "winkel", "artenschutz","fängen" -- see new test case) failed to resolve.

@tsamaya
Copy link
Contributor

tsamaya commented Oct 19, 2015

Strange, I tested without URLEncode an d without error with these 3 words : winkel. artenschutz. fängen

    public void testNonAsciiCharactersDE() {
        What3Words w3w = new What3Words(API_KEY, "de");
        String[] words = {"winkel", "artenschutz", "fängen"};
        double[] coords;
        try {
            coords = w3w.wordsToPosition(words);
            assertEquals(2, coords.length);
            assertEquals(49.423903, coords[0]);
            assertEquals(8.282732, coords[1]);
        } catch (Exception e) {
            assertTrue(false);
        }
    }

I added a FR test with

    public void testNonAsciiCharatersFR() {
        What3Words w3w = new What3Words(API_KEY, "fr");
        String[] words = {"noël", "étain", "rizière"};
        double[] coords;
        try {
            coords = w3w.wordsToPosition(words);
            assertEquals(2, coords.length);
            assertEquals(-21.951124, coords[0]);
            assertEquals(166.685219, coords[1]);
        } catch (Exception e) {
            assertTrue(false);
        }
    }

let's see what @chrismayer think about all of that.

@jstastny
Copy link
Contributor Author

According to the comments in the thread: http://stackoverflow.com/questions/10786042/java-url-encoding-of-query-string-parameters, using the URLEncode.encode to encode URL is not the best way to encode query params. It is best explained here: http://stackoverflow.com/a/16226168/3730269

I will send a different merge request with the correct solution to this issue.

@jstastny jstastny closed this Oct 19, 2015
@jstastny
Copy link
Contributor Author

Having done some more research on how to escape query parameters with plain Java (not using any external library as I otherwise do), it seems that the solution used in this merge request is probably one of the best.

Surely, it is better that having no encoding of the query params at all. I am therefore reopening this. If somebody finds a better way to encode parameters with plain Java, they can contribute another merge request.

@jstastny jstastny reopened this Oct 19, 2015
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

Successfully merging this pull request may close these issues.

2 participants