From e885288a97b2e6191aa9f0d64a8a2268d0a079ab Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Thu, 9 Dec 2021 15:12:55 -0500 Subject: [PATCH] Avoid modifying string literals When used in an environment frozen string literals (for example: RUBYOPT="--enable=frozen-string-literal") modifying "" raises exceptions. This fixes that, by switching to String.new. --- lib/otnetstring.rb | 2 +- lib/rb-fsevent/fsevent.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/otnetstring.rb b/lib/otnetstring.rb index cd8de4c..7623d67 100644 --- a/lib/otnetstring.rb +++ b/lib/otnetstring.rb @@ -28,7 +28,7 @@ class << self def parse(io, encoding = 'internal', fallback_encoding = nil) fallback_encoding = io.encoding if io.respond_to? :encoding io = StringIO.new(io) if io.respond_to? :to_str - length, byte = "", nil + length, byte = String.new, nil while byte.nil? || byte =~ /\d/ length << byte if byte diff --git a/lib/rb-fsevent/fsevent.rb b/lib/rb-fsevent/fsevent.rb index 23c5aa9..5c1ea3f 100644 --- a/lib/rb-fsevent/fsevent.rb +++ b/lib/rb-fsevent/fsevent.rb @@ -44,8 +44,8 @@ def run while @running && IO::select([@pipe], nil, nil, nil) # managing the IO ourselves allows us to be careful and never pass an # incomplete message to OTNetstring.parse() - message = "" - length = "" + message = String.new + length = String.new byte = nil reading_length = true