rails/rails — pull request #18236 by vipulnsward (2014-12-29 13:03:33+00:00)
Title: Fix html_safe string access modifying frozen values

When trying to access a character on a string buffer object via `:[]`, if the object being accessed currently returns `html_safe?` as true, we used to set `@html_safe` variable as true on new object created. When doing something like
```ruby
x = 'Hello'.html_safe
x[/a/, 1]
```
would throw an error on ruby 2.2, since when nothing gets matched, `nil` is returned by the code and it tries to set `@html_safe` value to true, which would error since starting ruby 2.2 nil is frozen.

This change adds a safety net to avoid setting `@html_safe = true` on frozen objects.

Fixes #18235