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

x = 'Hello'.html_safe
x[/a/, 1]

would throw an error on ruby 2.2, since when nothign gets matched nil is returned by the code and it tries to set   `@html_safe` value to true,
which would error since starting 2.2 nil is frozen.

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

Fixes #18235
Merge pull request #18236 from vipulnsward/dont-eval-frozen

Fix html_safe string access modifying frozen values
Just check if the buffer exists before changing it