New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SafeBuffer#gsub breaks block form match variables $1, $2, $`, $&, and $’ #1046

Closed
hooopo opened this Issue Feb 4, 2013 · 0 comments

Comments

Projects
None yet
2 participants
@hooopo
Contributor

hooopo commented Feb 4, 2013

SafeBuffer#gsub breaks js_escape_html method:

[28] pry(main)> require 'active_support/core_ext/string/output_safety'
=> false
[29] pry(main)> html = ActiveSupport::SafeBuffer.new('<a href="http://ask.csdn.net">"s"</a>')
=> "<a href=\"http://ask.csdn.net\">\"s\"</a>"
[30] pry(main)> javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
=> {"\\"=>"\\\\",
 "</"=>"<\\/",
 "\r\n"=>"\\n",
 "\n"=>"\\n",
 "\r"=>"\\n",
 "\""=>"\\\"",
 "'"=>"\\'"}
[31] pry(main)> html.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { javascript_mapping[$1] }
=> "<a href=http://ask.csdn.net>sa>"
[32] pry(main)> html.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { p $1}
"s"
"s"
"s"
"s"
"s"
=> "<a href=shttp://ask.csdn.nets>ssssa>"
[33] pry(main)> html.gsub(/(\\|<\/|\r\n|[\n\r"'])/) {|m| p m}
"\""
"\""
"\""
"\""
"</"

related issue: rails/rails#1555

@ghost ghost assigned skade Feb 4, 2013

dariocravero added a commit that referenced this issue Feb 8, 2013

@hooopo hooopo closed this Feb 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment