title: What's valid and what's not in a URI query?
body: <h1>Background (question further down)</h1>
  <p>I've been Googling this back and forth reading RFCs and SO questions trying to crack this, but I still don't got jack.</p>
  <p>So I guess we just vote for the &quot;best&quot; answer and that's it, or?</p>
  <p>Basically it boils down to this.</p>
  <blockquote>
  <p>3.4. Query Component</p>
  <p>The query component is a string of information to be interpreted by the resource.</p>
  <p><code>query         = *uric</code></p>
  <p>Within a query component, the characters &quot;;&quot;, &quot;/&quot;, &quot;?&quot;, &quot;:&quot;, &quot;@&quot;, &quot;&amp;&quot;, &quot;=&quot;, &quot;+&quot;, &quot;,&quot;, and &quot;$&quot; are reserved.</p>
  </blockquote>
  <p>The first thing that boggles me is that *uric is defined like this</p>
  <blockquote>
  <p><code>uric          = reserved | unreserved | escaped</code></p>
  <p><code>reserved      = &quot;;&quot; | &quot;/&quot; | &quot;?&quot; | &quot;:&quot; | &quot;@&quot; | &quot;&amp;&quot; | &quot;=&quot; | &quot;+&quot; | &quot;$&quot; | &quot;,&quot;</code></p>
  </blockquote>
  <p>This is however somewhat clarified by paragraphs such as</p>
  <blockquote>
  <p>The &quot;reserved&quot; syntax class above refers to those characters that are allowed within a URI, but which may not be allowed within a particular component of the generic URI syntax; they are used as delimiters of the components described in Section 3.</p>
  <p>Characters in the &quot;reserved&quot; set are not reserved in all contexts. The set of characters actually reserved within any given URI component is defined by that component. In general, a character is reserved if the semantics of the URI changes if the character is replaced with its escaped US-ASCII encoding.</p>
  </blockquote>
  <p>This last excerpt feels somewhat backwards, but it clearly states that the reserved character set depends on context. Yet 3.4 states that all the reserved characters are reserved within a query component, however, the only things that would change the semantics here is escaping the question mark (?) as URIs do not define the concept of a query string.</p>
  <p>At this point I've given up on the RFCs entirely but found RFC 1738 particularly interesting.</p>
  <blockquote>
  <p>An HTTP URL takes the form:</p>
  <p><code>http://&lt;host&gt;:&lt;port&gt;/&lt;path&gt;?&lt;searchpart&gt;</code></p>
  <p>Within the &lt;path&gt; and &lt;searchpart&gt; components, &quot;/&quot;, &quot;;&quot;, &quot;?&quot; are reserved. The &quot;/&quot; character may be used within HTTP to designate a hierarchical structure.</p>
  </blockquote>
  <p>I interpret this at least with regards to HTTP URLs that RFC 1738 supersedes RFC 2396. Because the URI query has no notion of a query string also the interpretation of reserved doesn't really let allow me to define query strings as I'm used to doing by now.</p>
  <h1>Question</h1>
  <p>This all started when I wanted to pass a list of numbers together with the request of another resource. I didn't think much of it, and just passed it as a comma separated values. To my surprise though the comma was escaped. The query <code>page.html?q=1,2,3</code> encoded turned into <code>page.html?q=1%2C2%2C3</code> it works, but it's ugly and didn't expect it. That's when I started going through RFCs.</p>
  <p>My first question is simply, is encoding commas really necessary?</p>
  <p>My answer, according to RFC 2396: yes, according to RFC 1738: no</p>
  <p>Later I found related posts regarding the passing of lists between requests. Where the csv approach was poised as bad. This showed up instead, (haven't seen this before).</p>
  <pre><code>page.html?q=1;q=2;q=3
  </code></pre>
  <p>My second question, is this a valid URL?</p>
  <p>My answer, according to RFC 2396: no, according to RFC 1738: no (; is reserved)</p>
  <p>I don't have any issues with passing csv as long as it's numbers, but yes you do run into the risk of having to encode and decode values back and forth if the comma suddenly is needed for something else. Anyway I tried the semi-colon query string thing with ASP.NET and the result was not what I expected.</p>
  <pre><code>Default.aspx?a=1;a=2&amp;b=1&amp;a=3
  
  Request.QueryString[&quot;a&quot;] = &quot;1;a=2,3&quot;
  Request.QueryString[&quot;b&quot;] = &quot;1&quot;
  </code></pre>
  <p>I fail to see how this greatly differs from a csv approach as when I ask for &quot;a&quot; I get a string with commas in it. ASP.NET certainly is not a reference implementation but it hasn't let me down yet.</p>
  <p>But most importantly -- my third question -- where is specification for this? and what would you do or for that matter not do?</p>