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

[UrlBuilder] Slash handling in URL parameters #419

Open
sebez opened this issue Nov 2, 2017 · 2 comments
Open

[UrlBuilder] Slash handling in URL parameters #419

sebez opened this issue Nov 2, 2017 · 2 comments
Assignees
Labels

Comments

@sebez
Copy link
Contributor

sebez commented Nov 2, 2017

Current behaviour

Let an autocompletion service that uses a string URL parameter :

searchConstructeurByText(text) {
        return serveur.get(racine + 'searchConstructeurByText/${text}', { text });
}

If the user uses the / character in the input text:

  • it is not URL encoded
    • text = zorro/bernardo => searchConstructeurByText/zorro/bernardo
  • this changes the route to searchConstructeurByText/${param1}/${param2}
  • as the route doesn't exist, the server responds with a 404 error

A solution might be to encode manually the / character with %2F (URL encode for /).

This removes the 404 error but the server might be configured to forbid %2F and returns a 400 error.

https://stackoverflow.com/questions/4069002/receive-an-http-400-error-if-2f-is-part-of-the-get-url-in-jboss

A rather rude workaround would be to change the service to a POST and not use the URL parameter.

Expected behaviour

focus-core/util/url/builder should handle seamlessly URL parameter with an /.

Versions

Focus-core: 2.1.1

@Hartorn Hartorn self-assigned this Nov 2, 2017
@Hartorn Hartorn added the Bug label Nov 2, 2017
@Hartorn
Copy link
Contributor

Hartorn commented Nov 2, 2017

@sebez The param should be encoded, that's sure.
I think is is done in api-driver, but it's true it should be done in builder function.
We are gonna correct this

Although, in your use case, you should be using a query string, like /searchConstructeurByText?query=${text}, with text encoded.

I am wondering if the limitations on %2f is only for path part, and not the query string.

In .NET, you can get the result by having a parameter named query, with [FromUri] attribute

We are currently working on adding better solution for query, like giving a queryObj property in fetch options, which is directly building the query string, for either a text or an object, etc.

If you need the method to encode, or see what we are doing, you can see there
https://github.com/KleeGroup/focus-core/blob/api-driver/src/network/api-driver.js#L21

@sebez
Copy link
Contributor Author

sebez commented Nov 3, 2017

@Hartorn Thank you, /searchConstructeurByText?query=${text} indeed works without 400 error.

@AdrienViala AdrienViala assigned c3dr0x and unassigned Hartorn and c3dr0x Oct 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants