haskell-servant / haskell-servant/servant

QueryParam doesn't conform to HTTP

Open
#1,626 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
2k
Forks
427
Avg merge
2d 23h
Merged PRs (30d)
5

Description

Instance HasClient QueryParam' uses this function

```hs
encodeQueryParam :: ToHttpApiData a => a -> BS.ByteString
encodeQueryParam = BL.toStrict . toLazyByteString . toEncodedUrlPiece
```

where `toEncodedUrlPiece` is from `http-api-data` package, where it is documented to be applicable to path segments only, not to query parameters. As a result, if we try to send a simple text string as a parameter,

```hs
type API = QueryParam "p" Text
```

this will be encoded as `?p=a%20+%20b` which is wrong, because `+` is the encoding for the space, and `+` must be encoded as `%2B`.

`?p=a%20+%20b` is interpreted by a standard-conforming server as `p = "a b"`.

`p = "a + b"` must be encoded as `?p=a+%2B+b`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.