Don't call gsub on safe strings

Updated . Posted . Visible to the public.

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.

Henning Koch
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2011-10-17 13:46)