Created
June 16, 2011 19:42
-
-
Save jstraitiff-wk/1030065 to your computer and use it in GitHub Desktop.
rails 3.0.9 problem with setting $1, etc. vars on h'd text
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
ruby-1.9.2-p136 :057 > def linkify_it(txt) | |
ruby-1.9.2-p136 :058?> safe_text = ERB::Util::h(txt) | |
ruby-1.9.2-p136 :059?> safe_text.gsub(/(^|\s)(https?:\/\/([^\s\/]*)\S*)(\s|$)/i) {|m| puts "safe txt: match '#{m}', $1 '#{$1}', $2 '#{$2}', $3 '#{$3}', $4 '#{$4}'"} | |
ruby-1.9.2-p136 :060?> txt.gsub(/(^|\s)(https?:\/\/([^\s\/]*)\S*)(\s|$)/i) {|m| puts "unsafe txt: match '#{m}', $1 '#{$1}', $2 '#{$2}', $3 '#{$3}', $4 '#{$4}'"} | |
ruby-1.9.2-p136 :061?> end | |
=> nil | |
ruby-1.9.2-p136 :062 > linkify_it(a) | |
safe txt: match ' hTTp://google.com ', $1 '', $2 '', $3 '', $4 '' | |
unsafe txt: match ' hTTp://google.com ', $1 ' ', $2 'hTTp://google.com', $3 'google.com', $4 ' ' | |
=> "try thisit is fun" | |
ruby-1.9.2-p136 :063 > a | |
=> "try this hTTp://google.com it is fun" | |
ruby-1.9.2-p136 :064 > linkify_it("try this hTTp://google.com it is fun") | |
safe txt: match ' hTTp://google.com ', $1 '', $2 '', $3 '', $4 '' | |
unsafe txt: match ' hTTp://google.com ', $1 ' ', $2 'hTTp://google.com', $3 'google.com', $4 ' ' | |
=> "try thisit is fun" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment