Skip to content

Instantly share code, notes, and snippets.

@srinivasmohan
Created August 2, 2013 20:18

Revisions

  1. srinivasmohan created this gist Aug 2, 2013.
    27 changes: 27 additions & 0 deletions uri-encode
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    [smohan@dhcpa-111 ~]$ irb
    irb(main):001:0> require 'uri'
    => true
    irb(main):002:0> p URI::Parser.new.regexp[:UNSAFE]
    /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
    => /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]/
    irb(main):003:0> p Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@'])
    /(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
    => /(?-mix:[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]])|~|@/
    irb(main):004:0>
    irb(main):005:0*
    irb(main):006:0*
    irb(main):007:0*
    irb(main):008:0* puts URI::encode("/touch/123~ipad.png")
    /touch/123~ipad.png
    => nil
    irb(main):009:0> puts URI::encode("/touch/123~ipad.png", Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@']))
    /touch/123%7Eipad.png
    => nil
    irb(main):010:0> puts URI::encode("/touch/[email protected]")
    /touch/[email protected]
    => nil
    irb(main):011:0> puts URI::encode("/touch/[email protected]", Regexp.union([URI::Parser.new.regexp[:UNSAFE],'~','@']))
    /touch/123%40ipad.png
    => nil
    irb(main):012:0>
    [smohan@dhcpa-111 ~]$