From 4d033495bd96e27c7e3f4e13cc2e0cf03aa6b372 Mon Sep 17 00:00:00 2001 From: Tony Drake Date: Sat, 4 Jan 2025 12:49:47 -0500 Subject: [PATCH 1/2] Support current minitest and hoe gems --- Rakefile | 1 + test/helper.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 97daf96..e519071 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ Hoe.plugin :gemspec Hoe.spec('ruby-mp3info') do developer "Guillaume Pierronnet", "guillaume.pierronnet@gmail.com" + self.urls = {} end # vim: syntax=Ruby diff --git a/test/helper.rb b/test/helper.rb index ac5c3a0..9e5678c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -3,6 +3,10 @@ TestCase = Test::Unit::TestCase else require 'minitest/autorun' - TestCase = MiniTest::Test + if defined?(MiniTest) + TestCase = MiniTest::Test + else + TestCase = Minitest::Test + end end From 53ebc05e94b898abd1517138e1d8e72979f92d23 Mon Sep 17 00:00:00 2001 From: Tony Drake Date: Sat, 4 Jan 2025 13:07:48 -0500 Subject: [PATCH 2/2] Remove Ruby 3.4 warnings - Added frozen_string_literal magic comment to id3v2.rb and the test file. - Converted strings being mutated to using String.new to allow mutating. --- lib/mp3info.rb | 2 +- lib/mp3info/id3v2.rb | 33 +++++++++++++++++---------------- test/test_ruby-mp3info.rb | 13 +++++++------ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/mp3info.rb b/lib/mp3info.rb index 1651486..d2d94ad 100644 --- a/lib/mp3info.rb +++ b/lib/mp3info.rb @@ -489,7 +489,7 @@ def each_frame loop do frame = find_next_frame yield frame - @io.seek(frame[:size] -4, File::SEEK_CUR) + @io.seek(frame[:size] - 4, File::SEEK_CUR) #puts "frame #{frame_count} len #{frame[:length]} br #{frame[:bitrate]} @io.pos #{@io.pos}" break if @io.eof? end diff --git a/lib/mp3info/id3v2.rb b/lib/mp3info/id3v2.rb index f2d5e4b..7b56188 100644 --- a/lib/mp3info/id3v2.rb +++ b/lib/mp3info/id3v2.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: true # License:: Ruby # Author:: Guillaume Pierronnet (mailto:guillaume.pierronnet@gmail.com) @@ -243,11 +244,11 @@ def add_picture(data, opts = {}) :description => "image" } options.update(opts) - jpg = Regexp.new( "^\xFF".force_encoding("BINARY"), + jpg = Regexp.new( String.new("^\xFF").force_encoding("BINARY"), Regexp::FIXEDENCODING ) - png = Regexp.new( "^\x89PNG".force_encoding("BINARY"), + png = Regexp.new( String.new("^\x89PNG").force_encoding("BINARY"), Regexp::FIXEDENCODING ) - gif = Regexp.new( "^\x89GIF".force_encoding("BINARY"), + gif = Regexp.new( String.new("^\x89GIF").force_encoding("BINARY"), Regexp::FIXEDENCODING ) mime = options[:mime] @@ -277,10 +278,10 @@ def pictures next if !pic.is_a?(String) or pic == "" pic.force_encoding 'BINARY' picture = [] - jpg_regexp = Regexp.new("jpg|JPG|jpeg|JPEG|jfif|JFIF".force_encoding("BINARY"), + jpg_regexp = Regexp.new(String.new("jpg|JPG|jpeg|JPEG|jfif|JFIF").force_encoding("BINARY"), Regexp::FIXEDENCODING ) - png_regexp = Regexp.new("png|PNG".force_encoding("BINARY"), + png_regexp = Regexp.new(String.new("png|PNG").force_encoding("BINARY"), Regexp::FIXEDENCODING ) header = pic.unpack('a120').first.force_encoding "BINARY" mime_pos = 0 @@ -289,18 +290,18 @@ def pictures if header.match jpg_regexp and not header.match png_regexp mime = "jpg" mime_pos = header =~ jpg_regexp - start = Regexp.new("\xFF\xD8".force_encoding("BINARY"), + start = Regexp.new(String.new("\xFF\xD8").force_encoding("BINARY"), Regexp::FIXEDENCODING ) - start_with_anchor = Regexp.new("^\xFF\xD8".force_encoding("BINARY"), + start_with_anchor = Regexp.new(String.new("^\xFF\xD8").force_encoding("BINARY"), Regexp::FIXEDENCODING ) end if header.match png_regexp and not header.match jpg_regexp mime = "png" mime_pos = header =~ png_regexp - start = Regexp.new("\x89PNG".force_encoding("BINARY"), + start = Regexp.new(String.new("\x89PNG").force_encoding("BINARY"), Regexp::FIXEDENCODING ) - start_with_anchor = Regexp.new("^\x89PNG".force_encoding("BINARY"), + start_with_anchor = Regexp.new(String.new("^\x89PNG").force_encoding("BINARY"), Regexp::FIXEDENCODING ) end @@ -315,11 +316,11 @@ def pictures if mime == "jpg" # inspect jpg image header (first 10 chars) for "\xFF\x00" (expect "\xFF") - trailing_null_byte = Regexp.new("(\377)(\000)".force_encoding('BINARY'), + trailing_null_byte = Regexp.new(String.new("(\377)(\000)").force_encoding('BINARY'), Regexp::FIXEDENCODING) md = data =~ trailing_null_byte if !md.nil? and md < 10 - data.gsub!(trailing_null_byte, "\xff".force_encoding('BINARY')) + data.gsub!(trailing_null_byte, String.new("\xff").force_encoding('BINARY')) end end else @@ -384,7 +385,7 @@ def to_bin #TODO add of crc #TODO add restrictions tag - tag = "" + tag = String.new @hash.each do |k, v| next unless v next if v.respond_to?("empty?") and v.empty? @@ -410,7 +411,7 @@ def to_bin end end - tag_str = "ID3" + tag_str = String.new("ID3") #version_maj, version_min, unsync, ext_header, experimental, footer tag_str << [ 3, 0, "0000" ].pack("CCB4") tag_str << [to_syncsafe(tag.size)].pack("N") @@ -458,8 +459,8 @@ def decode_tag(name, raw_value) split_str = "\x00" end head, tail = raw_tag.split(split_str) - if head == "\xFF\xFE".force_encoding('binary') - rgx = Regexp.new("^\xFF\xFE\x00\x00".force_encoding("BINARY")) + if head == String.new("\xFF\xFE").force_encoding('binary') + rgx = Regexp.new(String.new("^\xFF\xFE\x00\x00").force_encoding("BINARY")) out = raw_tag.sub(rgx, '') elsif tail out = tail @@ -591,7 +592,7 @@ def to_syncsafe(num) ### this is especially useful for printing out APIC data because ### only the header of the APIC tag is of interest def pretty_header(str, chars=128) - "#{str.unpack("a#{chars}").first}<<<...snip...>>>".inspect[1..-2] + "#{str.unpack(String.new("a#{chars}")).first}<<<...snip...>>>".inspect[1..-2] end end diff --git a/test/test_ruby-mp3info.rb b/test/test_ruby-mp3info.rb index 233c248..80752a6 100755 --- a/test/test_ruby-mp3info.rb +++ b/test/test_ruby-mp3info.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby # encoding: utf-8 +# frozen_string_literal: true dir = File.dirname(__FILE__) $:.unshift("#{dir}/../lib/") @@ -208,7 +209,7 @@ def test_id3v2_to_inspect_hash end def test_id3v2_get_pictures_png - img = "\x89PNG".force_encoding('BINARY') + + img = String.new("\x89PNG").force_encoding('BINARY') + random_string(120).force_encoding('BINARY') Mp3Info.open(TEMP_FILE) do |mp3| mp3.tag2.add_picture(img, :description => 'example image.png') @@ -219,7 +220,7 @@ def test_id3v2_get_pictures_png end def test_id3v2_get_pictures_png_bad_mime - img = "\x89PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0001\b\u0002\u0000\u0000\u0000\x90wS\xDE\u0000\u0000\u0000\fIDAT\b\xD7c\xF8\xFF\xFF?\u0000\u0005\xFE\u0002\xFE\xDC\xCCY\xE7\u0000\u0000\u0000\u0000IEND\xAEB`\x82".force_encoding('BINARY') + img = String.new("\x89PNG\r\n\u001A\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000\u0001\u0000\u0000\u0000\u0001\b\u0002\u0000\u0000\u0000\x90wS\xDE\u0000\u0000\u0000\fIDAT\b\xD7c\xF8\xFF\xFF?\u0000\u0005\xFE\u0002\xFE\xDC\xCCY\xE7\u0000\u0000\u0000\u0000IEND\xAEB`\x82").force_encoding('BINARY') Mp3Info.open(TEMP_FILE) do |mp3| mp3.tag2.add_picture(img, :description => 'example image.png', :mime => 'jpg') end @@ -230,7 +231,7 @@ def test_id3v2_get_pictures_png_bad_mime end def test_id3v2_get_pictures_jpg - img = "\xFF\xD8".force_encoding('BINARY') + + img = String.new("\xFF\xD8").force_encoding('BINARY') + random_string(120).force_encoding('BINARY') Mp3Info.open(TEMP_FILE) do |mp3| @@ -243,7 +244,7 @@ def test_id3v2_get_pictures_jpg end def test_id3v2_get_pictures_jpg_bad_mime - img = "\xFF\xD8".force_encoding('BINARY') + + img = String.new("\xFF\xD8").force_encoding('BINARY') + random_string(120).force_encoding('BINARY') Mp3Info.open(TEMP_FILE) do |mp3| @@ -256,7 +257,7 @@ def test_id3v2_get_pictures_jpg_bad_mime end def test_id3v2_remove_pictures - jpg_data = "\xFF\xD8".force_encoding('BINARY') + + jpg_data = String.new("\xFF\xD8").force_encoding('BINARY') + random_string(123).force_encoding('BINARY') Mp3Info.open(TEMP_FILE) do |mp| mp.tag2.add_picture(jpg_data) @@ -587,7 +588,7 @@ def write_tag2_to_temp_file(tag) end def random_string(size) - out = "" + out = String.new size.times { out << rand(256).chr } out end