diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index 3ded0e87..bcf3f48d 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -37,20 +37,26 @@ class InvalidURIError < StandardError ## # Container for the character classes specified in # RFC 3986. + # + # Note: Concatenated and interpolated `String`s are not affected by the + # `frozen_string_literal` directive and must be frozen explicitly. + # + # Interpolated `String`s *were* frozen this way before Ruby 3.0: + # https://bugs.ruby-lang.org/issues/17104 module CharacterClasses ALPHA = "a-zA-Z" DIGIT = "0-9" GEN_DELIMS = "\\:\\/\\?\\#\\[\\]\\@" SUB_DELIMS = "\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=" - RESERVED = GEN_DELIMS + SUB_DELIMS - UNRESERVED = ALPHA + DIGIT + "\\-\\.\\_\\~" - PCHAR = UNRESERVED + SUB_DELIMS + "\\:\\@" - SCHEME = ALPHA + DIGIT + "\\-\\+\\." - HOST = UNRESERVED + SUB_DELIMS + "\\[\\:\\]" - AUTHORITY = PCHAR + "\\[\\]" - PATH = PCHAR + "\\/" - QUERY = PCHAR + "\\/\\?" - FRAGMENT = PCHAR + "\\/\\?" + RESERVED = (GEN_DELIMS + SUB_DELIMS).freeze + UNRESERVED = (ALPHA + DIGIT + "\\-\\.\\_\\~").freeze + PCHAR = (UNRESERVED + SUB_DELIMS + "\\:\\@").freeze + SCHEME = (ALPHA + DIGIT + "\\-\\+\\.").freeze + HOST = (UNRESERVED + SUB_DELIMS + "\\[\\:\\]").freeze + AUTHORITY = (PCHAR + "\\[\\:\\]").freeze + PATH = (PCHAR + "\\/").freeze + QUERY = (PCHAR + "\\/\\?").freeze + FRAGMENT = (PCHAR + "\\/\\?").freeze end module NormalizeCharacterClasses diff --git a/spec/addressable/uri_spec.rb b/spec/addressable/uri_spec.rb index b8ca5213..32e2ff4c 100644 --- a/spec/addressable/uri_spec.rb +++ b/spec/addressable/uri_spec.rb @@ -6667,3 +6667,13 @@ def to_str expect(@uri.class).to eq(@uri.join('path').class) end end + +describe Addressable::URI, "when initialized in a non-main `Ractor`" do + it "should have the same value as if used in the main `Ractor`" do + pending("Ruby 3.0+ for `Ractor` support") unless defined?(Ractor) + main = Addressable::URI.parse("http://example.com") + expect( + Ractor.new { Addressable::URI.parse("http://example.com") }.take + ).to eq(main) + end +end