faye / websocket-driver-ruby

WebSocket protocol handler with pluggable I/O
Other
223 stars 43 forks source link

Flag files that modify string literals #85

Closed danielmorrison closed 2 years ago

danielmorrison commented 3 years ago

When running in an environment that freezes string literals by default, hybi.rb raises exceptions as it modifies the format = 'C2' string (line 224).

Adding the magic comment supports this use case without modifying behavior for anyone else. I added it to one spec too, so that running specs this way (RUBYOPT="--enable=frozen-string-literal" rspec) keeps them all passing.

jcoglan commented 2 years ago

Thank you @danielmorrison :)

jcoglan commented 2 years ago

Out of curiosity, would it also work for you if this library didn't use bare string literals but used new string objects, i.e. String.new("literal data")?

danielmorrison commented 2 years ago

Out of curiosity, would it also work for you if this library didn't use bare string literals but used new string objects, i.e. String.new("literal data")?

It would. I tried to pick the least-invasive syntax to avoid any bike shedding.