title: Ruby - URL encoding
body: <p>I have a URL string where there are line breaks and carriage returns. E.g.</p>
  
  <pre><code>http://xyz.com/hello?name=john&amp;msg=hello\nJohn\n\rgoodmorning&amp;note=last\night I went to \roger
  </code></pre>
  
  <p>Where my actual <code>msg</code> string is:</p>
  
  <pre><code>hello
  john
  goodmorning
  </code></pre>
  
  <p>and <code>note</code> string is</p>
  
  <pre><code>last\night I went to \roger
  </code></pre>
  
  <p>In order to send it correctly I have to urlencode this</p>
  
  <pre><code> http://xyz.com/hello?name%3Djohn%26msg%3Dhello%5CnJohn%5Cn%5Crgoodmorning%26note%3Dlast%5Cnight%20I%20went%20to%20%5Croger
  </code></pre>
  
  <p>But this encode mess up \n and \r. While I expect \n should get converted to %0A and \r to %0D</p>
  
  <p>I am writing code is ruby. And I tried to take help of <code>Addressable::URI</code> but no help yet. Other way could be replacing \n and \r manually to %0A and %0D respectively. But that replacement can replace valid character such as <code>last\night</code> to <code>last%0Aight</code> that I don't want. Can anyone suggest a better solution? Thanks.</p>