Calling #gsub on a string that was previously marked as #html_safe will lead to unexpected behavior. E. g. backreferences to captured groups ($1, $2) will be nil even if the group was matched.
There is no universal workaround available since you can't expect
#html_safe strings
Show archive.org snapshot
to still be safe after using gsub on them.
You can, however, fix the $1 gsub behavior on html_safe strings.
Posted by Henning Koch to makandra dev (2011-10-17 13:46)