Created
August 2, 2013 20:18
-
-
Save srinivasmohan/6143115 to your computer and use it in GitHub Desktop.
Add to unsafe characters to force them to be encoded - Ruby 1.9.x URI.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 ~]$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment