srt icon indicating copy to clipboard operation
srt copied to clipboard

[BUG] uriparser should decode pct-encoded

Open wakabayashik opened this issue 4 years ago • 2 comments

Describe the bug uriparser should decode pct-encoded

To Reproduce

  1. create an listener program with SRT-APIs (srt_listen, srt_accept...) and run as a listener.
  2. run "srt-live-transmit srt://192.168.1.1:12345?streamid=%23!::u=admin,r=bluesbrothers1_hi file://con | NUL" as a caller
  3. retrieve streamid by srt_getsockflag(s, SRTO_STREAMID, ...) on listener program.

Expected behavior streamid should become "#!::u=admin,r=bluesbrothers1_hi", but it is still "%23!::u=admin,r=bluesbrothers1_hi"

Desktop (please provide the following information):

  • OS: listener (Windows Server 2016)、caller (Windows 8.1)
  • SRT Version / commit ID: v1.4.1. (built it myself by vs2013 with some patches)

Additional context https://tools.ietf.org/html/rfc3986

         foo://example.com:8042/over/there?name=ferret#nose
         \_/   \______________/\_________/ \_________/ \__/
          |           |            |            |        |
       scheme     authority       path        query   fragment
          |   _____________________|__
         / \ /                        \
         urn:example:animal:ferret:nose

because '#' is delimiter of fragment part, the query cannot contain '#' without pct-encoding.

  • unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
  • sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
  • pct-encoded = "%" HEXDIG HEXDIG
  • pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
  • query = *( pchar / "/" / "?" )

wakabayashik avatar Mar 09 '20 02:03 wakabayashik

I recently ran into a similar issue where internal customers wanted to use reserved characters inside their stream ids, which need to be percent encoded to pass as a url parameter to apps like srt-live-transmit.

I wrote a quick percent decoder that I just applied to the query string keys and parameters that solved our issue when using srt-live-transmit. Basically, when the uriparser is parsing the query key-val pairs I just percent decode the keys and vals to ASCII / Latin-1 to be stored in the map of query parameters. I didn't tackle unicode / utf-8 encoding as the string types in the code probably aren't right for that.

This solved my problem and I'll gladly contribute it if you want it, but I'm not sure it is generally the best approach as your uriparser class also can reconstruct a url from its component pieces. I didn't write the matching encoding bit yet and I only applied the decoding to the query parameters. I'm not even sure that is the right place to do this.

Please advise.

jschultz410 avatar May 20 '21 17:05 jschultz410

More references on the topic: https://url.spec.whatwg.org/

maxsharabayko avatar Sep 13 '22 14:09 maxsharabayko

Resolved by #2015.

maxsharabayko avatar Sep 18 '23 14:09 maxsharabayko