Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

Commented Issue: uri_exception is thrown when uri contains square brackets [382]

$
0
0
`uri_builder` in `windows_request_context::read_headers_io_completion` throws web::uri_exception when the uri contains square brackets.

The encode_uri method handles square brackets as general delimiters and therefor will not encode them.
The encoded uri is passed to the uri_builder that throws the web::uri_exception.

The following code snippet reproduces the exception:
```cpp
auto encodedUri = uri::encode_uri(L"http://localhost/service[1]?param[]=123&param[]=456");
// assert(encodedUri == L"http://localhost/service%5B1%5D?param%5B%5D=123&param%5B%5D=456");
uri_builder builder(encodedUri);
```

In compare, the JavaScript `encodeURI` method encodes the square brackets as this exampel shows:
```javascript
console.log(encodeURI("http://localhost/service[1]?param[]=123&param[]=456"));
// -> http://localhost/service%5B1%5D?param%5B%5D=123&param%5B%5D=456
```

Is there a reason to keep the brackets unencoded and why is the behavior different to javascript?
Comments: Hi Markus, If the URI coming across wire has the square brackets percent encoded then the http_listener will leave the string as is and construct a web::uri object out of it. In that case the uri constructor won't throw an exception verifying. Of course if the URI coming across the wire has square brackets not percent encoded then the listener will respond with a bad request HTTP status. Perhaps I'm missing or overlooking something here? Thanks, Steve

Viewing all articles
Browse latest Browse all 4845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>