Skip to content

Instantly share code, notes, and snippets.

View jstraitiff-wk's full-sized avatar

jstraitiff-wk

View GitHub Profile
@jstraitiff-wk
jstraitiff-wk / gist:1030065
Created June 16, 2011 19:42
rails 3.0.9 problem with setting $1, etc. vars on h'd text
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"