Skip to content

Commit

Permalink
Avoid spurious frozen string literal warnings on Ruby 3.4.0-preview2
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Oct 8, 2024
1 parent 9375cc5 commit 6aa6f52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
=== master

* Avoid spurious frozen string literal warnings on Ruby 3.4.0-preview2 (jeremyevans)

=== 1.13.0 (2024-06-13)

* Define Erubi.h as a module function (jeremyevans)
Expand Down
19 changes: 14 additions & 5 deletions lib/erubi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,25 @@ def initialize(input, properties={})

private

if RUBY_VERSION >= '2.3'
def _dup_string_if_frozen(string)
+string
end
# :nocov:
else
def _dup_string_if_frozen(string)
string.frozen? ? string.dup : string
end
end
# :nocov:

# Add raw text to the template. Modifies argument if argument is mutable as a memory optimization.
# Must be called with a string, cannot be called with nil (Rails's subclass depends on it).
def add_text(text)
return if text.empty?

if text.frozen?
text = text.gsub(/['\\]/, '\\\\\&')
else
text.gsub!(/['\\]/, '\\\\\&')
end
text = _dup_string_if_frozen(text)
text.gsub!(/['\\]/, '\\\\\&')

with_buffer{@src << " << '" << text << @text_end}
end
Expand Down

0 comments on commit 6aa6f52

Please sign in to comment.