From 2cf5f420a08c0bc95277e3d54b1c6eee3523c24e Mon Sep 17 00:00:00 2001 From: Benjamin Turner Date: Thu, 9 Apr 2026 10:28:03 -0700 Subject: [PATCH 1/3] Clean up subs files after shortcut test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the same files would be written—and cleaned up—by several other tests, these files might or might not be left behind, depending on the order in which tests were run. --- tests/segmenter.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/segmenter.rb b/tests/segmenter.rb index b6ba8ea..2fe9221 100644 --- a/tests/segmenter.rb +++ b/tests/segmenter.rb @@ -53,9 +53,11 @@ def test_shortcut_method res = WebVTT.segment("tests/subtitles/test.vtt") assert_instance_of Array, res assert_equal 2, res.size - assert_equal 35, res[1].size + subs = res[1] + assert_equal 35, subs.size # clean up + subs.each {|f| FileUtils.rm(f.filename)} FileUtils.rm("prog_index.m3u8") end From 13c51da4bcd5ba46947a0988f4679e95fcd655f7 Mon Sep 17 00:00:00 2001 From: Benjamin Turner Date: Thu, 9 Apr 2026 10:32:59 -0700 Subject: [PATCH 2/3] Replace literals that get modified w/ String.new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Ruby 3.4, by default string literals are “chilled” and if a chilled string is modified, a warning is emitted (https://bugs.ruby-lang.org/issues/20205). Replace string literals that are intended to be modified with a call to String.new, which produces a fresh mutable string each invocation. --- lib/webvtt/parser.rb | 2 +- tests/parser.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/webvtt/parser.rb b/lib/webvtt/parser.rb index 388345a..19951c1 100644 --- a/lib/webvtt/parser.rb +++ b/lib/webvtt/parser.rb @@ -118,7 +118,7 @@ def self.parse(cue) end def to_webvtt - res = "" + res = String.new if @identifier res << "#{@identifier}\n" end diff --git a/tests/parser.rb b/tests/parser.rb index 75d9008..3216a9e 100644 --- a/tests/parser.rb +++ b/tests/parser.rb @@ -257,7 +257,7 @@ def test_build_cue cue.start = WebVTT::Timestamp.new 0 cue.end = WebVTT::Timestamp.new 12 cue.text = "Built from scratch" - output = "" + output = String.new output << "00:00:00.000 --> 00:00:12.000\n" output << "Built from scratch" assert_equal output, cue.to_webvtt From 19784ee32808d0f0e8873de56e6887fce1cb3d2f Mon Sep 17 00:00:00 2001 From: Benjamin Turner Date: Thu, 9 Apr 2026 10:35:31 -0700 Subject: [PATCH 3/3] Add frozen-string pragma to files This pragma is supported back to Ruby 2.3 and prohibits modifying string literals, which will (someday?) be frozen by default in Ruby. --- lib/webvtt.rb | 1 + lib/webvtt/parser.rb | 2 ++ lib/webvtt/segmenter.rb | 2 ++ tests/parser.rb | 2 ++ tests/segmenter.rb | 2 ++ 5 files changed, 9 insertions(+) diff --git a/lib/webvtt.rb b/lib/webvtt.rb index 29664bd..18d51df 100644 --- a/lib/webvtt.rb +++ b/lib/webvtt.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 +# frozen_string_literal: true if defined?(Encoding) Encoding.default_internal = Encoding.default_external = "UTF-8" diff --git a/lib/webvtt/parser.rb b/lib/webvtt/parser.rb index 19951c1..295c19a 100644 --- a/lib/webvtt/parser.rb +++ b/lib/webvtt/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module WebVTT def self.read(file) diff --git a/lib/webvtt/segmenter.rb b/lib/webvtt/segmenter.rb index 211ee0d..bb60e69 100644 --- a/lib/webvtt/segmenter.rb +++ b/lib/webvtt/segmenter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' module WebVTT diff --git a/tests/parser.rb b/tests/parser.rb index 3216a9e..316ef2f 100644 --- a/tests/parser.rb +++ b/tests/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH << "lib/" require "minitest/autorun" require "webvtt" diff --git a/tests/segmenter.rb b/tests/segmenter.rb index 2fe9221..949a48d 100644 --- a/tests/segmenter.rb +++ b/tests/segmenter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH << "lib/" require "minitest/autorun" require "webvtt"