title: should encodeURI ever be used?
body: <p>Is there any valid use for javascript's encodeURI function?</p>
  
  <p>As far as I can tell, when you are trying to make a HTTP request you should either have:</p>
  
  <ul>
  <li>a complete URI</li>
  <li>some fragment you want to put in a URI, which is either a unicode string or UTF-8 byte sequence</li>
  </ul>
  
  <p>In the first case, obviously nothing needs to be done to request it. Note: if you actually want to pass it as a parameter (e.g ?url=http...) then you actually have an instance of the second case that happens to look like a URI.</p>
  
  <p>In the second case, you should <em>always</em> convert a unicode string into UTF-8, and then call encodeURIComponent to escape <em>all</em> characters before adding it to a URI. (If you have a UTF-8 byte sequence instead of a unicode string you can skip the convert-to-utf8 step).</p>
  
  <p>Assuming I havent missed anything, I can't see a valid use for encodeURI. If you use it, it's likely you've constructed an invalid URI and then attempted to "sanitize" it after the fact, which is simply not possible since you don't know which characters were intended literally, and which were intended to be escaped.</p>
  
  <p>I have seen a lot of advice against using escape(), but don't see anybody discouraging encodeURI. Am I missing a valid use?</p>