Git Product home page Git Product logo

Comments (9)

adamw avatar adamw commented on May 22, 2024 1

No, you are right, somehow the + is not escaped correctly. I'll take a look tomorrow.

from sttp.

adamw avatar adamw commented on May 22, 2024

Hmm I suppose we'll need context-sensitive decoding, not only encoding, wich makes sense :) The + in the query string should be converted to a (space), but not in the path

from sttp.

anatoliykmetyuk avatar anatoliykmetyuk commented on May 22, 2024

By query string, do you mean the named URI parameters? Actually my use case is a URI as follows:

http://localhost:8081/user?phone=+123456

The context is looking up by phone that is. Come to think about it, "+" is really used as a space in this context. However, does it make sense to still have it as a space in sttp? After all, you can perfectly use spaces in query string and they will be encoded properly.

from sttp.

adamw avatar adamw commented on May 22, 2024

If you want to include + in the query string, it should be %-encoded, as + is the escaped form of space (in that context).

The interpolator assumes that when you write down a literal URI (as a String, without embedding any expressions), it's in encoded form - hence it decodes any special characters. So:

uri"http://localhost:8081/user?phone=+123456" will be parsed as an URI with a single query parameter phone with the value 123456

uri"http://localhost:8081/user?phone=${"+123456"}" will be parsed as an URI with a single query parameter phone with the value +123456

from sttp.

anatoliykmetyuk avatar anatoliykmetyuk commented on May 22, 2024

Hm, then this does not seem to be working with get requests (maybe also with others). When I do:

sttp.get(uri"http://localhost:8888/appointment?phone=${"+1234"}").send()

And on the server side (http4s):

  val root = Root / "appointment"
/*...*/
    case req @ GET -> `root` :? PhoneParam(phoneRaw) =>
      println(s"Raw request parameter: $phoneRaw")

This prints:

Raw request parameter:  1234

from sttp.

anatoliykmetyuk avatar anatoliykmetyuk commented on May 22, 2024

Ah, come to think about it this may be http4s issue.

from sttp.

adamw avatar adamw commented on May 22, 2024

I think it's an easy fix (only the + is problematic), see the commit. I'm publishing a snapshot (for some reason it gets published as 0.0.20-SNAPSHOT), but the release will definitely have to wait until tomorrow ;)

from sttp.

anatoliykmetyuk avatar anatoliykmetyuk commented on May 22, 2024

Awesome, thank you for the quick fix @adamw! I will check it out tomorrow.

from sttp.

adamw avatar adamw commented on May 22, 2024

Released 1.0.6

from sttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.