diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da675ed..c54299e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ master ] +env: + RUBYOPT: "--enable-frozen-string-literal --debug-frozen-string-literal" + jobs: test: diff --git a/lib/html_truncator.rb b/lib/html_truncator.rb index 85084d7..789cad6 100644 --- a/lib/html_truncator.rb +++ b/lib/html_truncator.rb @@ -33,10 +33,10 @@ def ellipsable? class Nokogiri::XML::Node def truncate(max, opts) - return ["", 1, opts] if max == 0 && !ellipsable? + return [+"", 1, opts] if max == 0 && !ellipsable? inner, remaining, opts = inner_truncate(max, opts) if inner.empty? - return [self_closing? ? to_html : "", max - remaining, opts] + return [self_closing? ? to_html : +"", max - remaining, opts] end children.remove add_child Nokogiri::HTML::DocumentFragment.parse(inner) @@ -44,7 +44,7 @@ def truncate(max, opts) end def inner_truncate(max, opts) - inner, remaining = "", max + inner, remaining = +"", max self.children.each do |node| txt, nb, opts = node.truncate(remaining, opts) remaining -= nb diff --git a/spec/html_truncator_spec.rb b/spec/html_truncator_spec.rb index 1099c40..a0ad991 100644 --- a/spec/html_truncator_spec.rb +++ b/spec/html_truncator_spec.rb @@ -15,6 +15,10 @@ let(:long_text) { "
Foo " + ("Bar Baz " * 100) + "Quux
" } let(:list_text) { "Foo: