@@ -169,8 +169,7 @@ def self.parse(str)
169169 def self . normalize_path ( path )
170170 output , input = "" , path . to_s
171171 if input . encoding != Encoding ::ASCII_8BIT
172- input = input . dup if input . frozen?
173- input = input . force_encoding ( Encoding ::ASCII_8BIT )
172+ input = input . dup . force_encoding ( Encoding ::ASCII_8BIT )
174173 end
175174 until input . empty?
176175 if input . match ( RDS_2A )
@@ -228,8 +227,7 @@ def initialize(*args, validate: false, canonicalize: false, **options)
228227 if uri
229228 @value = uri . to_s
230229 if @value . encoding != Encoding ::UTF_8
231- @value = @value . dup if @value . frozen?
232- @value . force_encoding ( Encoding ::UTF_8 )
230+ @value . dup . force_encoding ( Encoding ::UTF_8 )
233231 @value . freeze
234232 end
235233 else
@@ -842,16 +840,16 @@ def parse(value)
842840 user , password = userinfo . to_s . split ( ':' , 2 )
843841 host , port = hostport . to_s . split ( ':' , 2 )
844842
845- parts [ :scheme ] = ( scheme . force_encoding ( Encoding ::UTF_8 ) if scheme )
846- parts [ :authority ] = ( authority . force_encoding ( Encoding ::UTF_8 ) if authority )
847- parts [ :userinfo ] = ( userinfo . force_encoding ( Encoding ::UTF_8 ) if userinfo )
848- parts [ :user ] = ( user . force_encoding ( Encoding ::UTF_8 ) if user )
849- parts [ :password ] = ( password . force_encoding ( Encoding ::UTF_8 ) if password )
850- parts [ :host ] = ( host . force_encoding ( Encoding ::UTF_8 ) if host )
843+ parts [ :scheme ] = ( scheme . dup . force_encoding ( Encoding ::UTF_8 ) if scheme )
844+ parts [ :authority ] = ( authority . dup . force_encoding ( Encoding ::UTF_8 ) if authority )
845+ parts [ :userinfo ] = ( userinfo . dup . force_encoding ( Encoding ::UTF_8 ) if userinfo )
846+ parts [ :user ] = ( user . dup . force_encoding ( Encoding ::UTF_8 ) if user )
847+ parts [ :password ] = ( password . dup . force_encoding ( Encoding ::UTF_8 ) if password )
848+ parts [ :host ] = ( host . dup . force_encoding ( Encoding ::UTF_8 ) if host )
851849 parts [ :port ] = ( ::URI . decode ( port ) . to_i if port )
852- parts [ :path ] = ( path . to_s . force_encoding ( Encoding ::UTF_8 ) unless path . empty? )
853- parts [ :query ] = ( query [ 1 ..-1 ] . force_encoding ( Encoding ::UTF_8 ) if query )
854- parts [ :fragment ] = ( fragment [ 1 ..-1 ] . force_encoding ( Encoding ::UTF_8 ) if fragment )
850+ parts [ :path ] = ( path . to_s . dup . force_encoding ( Encoding ::UTF_8 ) unless path . empty? )
851+ parts [ :query ] = ( query [ 1 ..-1 ] . dup . force_encoding ( Encoding ::UTF_8 ) if query )
852+ parts [ :fragment ] = ( fragment [ 1 ..-1 ] . dup . force_encoding ( Encoding ::UTF_8 ) if fragment )
855853 end
856854
857855 parts
@@ -869,7 +867,7 @@ def scheme
869867 # @param [String, #to_s] value
870868 # @return [RDF::URI] self
871869 def scheme = ( value )
872- object [ :scheme ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
870+ object [ :scheme ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
873871 @value = nil
874872 self
875873 end
@@ -893,7 +891,7 @@ def user
893891 # @param [String, #to_s] value
894892 # @return [RDF::URI] self
895893 def user = ( value )
896- object [ :user ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
894+ object [ :user ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
897895 @object [ :userinfo ] = format_userinfo ( "" )
898896 @object [ :authority ] = format_authority
899897 @value = nil
@@ -919,7 +917,7 @@ def password
919917 # @param [String, #to_s] value
920918 # @return [RDF::URI] self
921919 def password = ( value )
922- object [ :password ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
920+ object [ :password ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
923921 @object [ :userinfo ] = format_userinfo ( "" )
924922 @object [ :authority ] = format_authority
925923 @value = nil
@@ -947,7 +945,7 @@ def host
947945 # @param [String, #to_s] value
948946 # @return [RDF::URI] self
949947 def host = ( value )
950- object [ :host ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
948+ object [ :host ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
951949 @object [ :authority ] = format_authority
952950 @value = nil
953951 self
@@ -1010,7 +1008,7 @@ def path=(value)
10101008 if value
10111009 # Always lead with a slash
10121010 value = "/#{ value } " if host && value . to_s . match? ( /^[^\/ ]/ )
1013- object [ :path ] = value . to_s . force_encoding ( Encoding ::UTF_8 )
1011+ object [ :path ] = value . to_s . dup . force_encoding ( Encoding ::UTF_8 )
10141012 else
10151013 object [ :path ] = nil
10161014 end
@@ -1069,7 +1067,7 @@ def query
10691067 # @param [String, #to_s] value
10701068 # @return [RDF::URI] self
10711069 def query = ( value )
1072- object [ :query ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
1070+ object [ :query ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
10731071 @value = nil
10741072 self
10751073 end
@@ -1093,7 +1091,7 @@ def fragment
10931091 # @param [String, #to_s] value
10941092 # @return [RDF::URI] self
10951093 def fragment = ( value )
1096- object [ :fragment ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
1094+ object [ :fragment ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
10971095 @value = nil
10981096 self
10991097 end
@@ -1118,7 +1116,7 @@ def authority
11181116 # @return [RDF::URI] self
11191117 def authority = ( value )
11201118 object . delete_if { |k , v | [ :user , :password , :host , :port , :userinfo ] . include? ( k ) }
1121- object [ :authority ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
1119+ object [ :authority ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
11221120 user ; password ; userinfo ; host ; port
11231121 @value = nil
11241122 self
@@ -1148,7 +1146,7 @@ def userinfo
11481146 # @return [RDF::URI] self
11491147 def userinfo = ( value )
11501148 object . delete_if { |k , v | [ :user , :password , :authority ] . include? ( k ) }
1151- object [ :userinfo ] = ( value . to_s . force_encoding ( Encoding ::UTF_8 ) if value )
1149+ object [ :userinfo ] = ( value . to_s . dup . force_encoding ( Encoding ::UTF_8 ) if value )
11521150 user ; password ; authority
11531151 @value = nil
11541152 self
@@ -1263,6 +1261,26 @@ def request_uri
12631261 return res
12641262 end
12651263
1264+ ##
1265+ # Dump of data needed to reconsitute this object using Marshal.load
1266+ # This override is needed to avoid serializing @mutex.
1267+ #
1268+ # @param [Integer] level The maximum depth of objects to dump.
1269+ # @return [String] The dump of data needed to reconsitute this object.
1270+ def _dump ( level )
1271+ value
1272+ end
1273+
1274+ ##
1275+ # Load dumped data to reconsitute marshaled object
1276+ # This override is needed to avoid serializing @mutex.
1277+ #
1278+ # @param [String] data The dump of data needed to reconsitute this object.
1279+ # @return [RDF::URI] The reconsituted object.
1280+ def self . _load ( data )
1281+ new ( data )
1282+ end
1283+
12661284 private
12671285
12681286 ##
@@ -1274,8 +1292,7 @@ def request_uri
12741292 # @return [String]
12751293 def normalize_segment ( value , expr , downcase = false )
12761294 if value
1277- value = value . dup if value . frozen?
1278- value = value . force_encoding ( Encoding ::UTF_8 )
1295+ value = value . dup . force_encoding ( Encoding ::UTF_8 )
12791296 decoded = ::URI . decode ( value )
12801297 decoded . downcase! if downcase
12811298 ::URI . encode ( decoded , /[^(?:#{ expr } )]/ )
0 commit comments