ruby-changes:34599
From: naruse <ko1@a...>
Date: Fri, 4 Jul 2014 03:00:32 +0900 (JST)
Subject: [ruby-changes:34599] naruse:r46680 (trunk): * lib/uri/generic.rb (URI::Generic#query=): remove validation, just
naruse 2014-07-04 03:00:08 +0900 (Fri, 04 Jul 2014) New Revision: 46680 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46680 Log: * lib/uri/generic.rb (URI::Generic#query=): remove validation, just escape. [Feature #2542] * lib/uri/generic.rb (URI::Generic#fragment=): ditto. * lib/uri/generic.rb (URI::Generic#check_query): removed. * lib/uri/generic.rb (URI::Generic#set_query): ditto. * lib/uri/generic.rb (URI::Generic#check_fragment): ditto. * lib/uri/generic.rb (URI::Generic#set_fragment): ditto. Modified files: trunk/ChangeLog trunk/lib/uri/generic.rb trunk/test/uri/test_generic.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46679) +++ ChangeLog (revision 46680) @@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jul 4 02:56:04 2014 NARUSE, Yui <naruse@r...> + + * lib/uri/generic.rb (URI::Generic#query=): remove validation, just + escape. [Feature #2542] + + * lib/uri/generic.rb (URI::Generic#fragment=): ditto. + + * lib/uri/generic.rb (URI::Generic#check_query): removed. + + * lib/uri/generic.rb (URI::Generic#set_query): ditto. + + * lib/uri/generic.rb (URI::Generic#check_fragment): ditto. + + * lib/uri/generic.rb (URI::Generic#set_fragment): ditto. + Thu Jul 3 12:40:22 2014 Nobuyoshi Nakada <nobu@r...> * configure.in (--with-static-linked-ext): fix for extensions to Index: lib/uri/generic.rb =================================================================== --- lib/uri/generic.rb (revision 46679) +++ lib/uri/generic.rb (revision 46680) @@ -196,9 +196,9 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L196 self.set_host(host) self.set_port(port) self.set_path(path) - self.set_query(query) + self.query = query self.set_opaque(opaque) - self.set_fragment(fragment) + self.fragment=(fragment) end if registry raise InvalidURIError, @@ -823,42 +823,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L823 end # - # check the query +v+ component for RFC2396 compliance - # and against the URI::Parser Regexp for :QUERY - # - # Can not have a opaque component defined, - # with a query component defined. - # - def check_query(v) - return v unless v - - # raise if both hier and opaque are not nil, because: - # absoluteURI = scheme ":" ( hier_part | opaque_part ) - # hier_part = ( net_path | abs_path ) [ "?" query ] - if @opaque - raise InvalidURIError, - "query conflicts with opaque" - end - - if v && v != '' && parser.regexp[:QUERY] !~ v - raise InvalidComponentError, - "bad component(expected query component): #{v}" - end - - return true - end - private :check_query - - # protected setter for the query component +v+ - # - # see also URI::Generic.query= - # - def set_query(v) - @query = v - end - protected :set_query - - # # == Args # # +v+:: @@ -867,9 +831,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L831 # == Description # # public setter for the query component +v+. - # (with validation) - # - # see also URI::Generic.check_query # # == Usage # @@ -882,9 +843,17 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L843 # #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/?id=1> # def query=(v) - check_query(v) - set_query(v) - v + return @query = nil unless v + raise InvalidURIError, "query conflicts with opaque" if @opaque + + x = v.to_str + v = x.dup if x.equal? v + v.encode!(Encoding::UTF_8) rescue nil + v.delete!("\t\r\n") + v.force_encoding(Encoding::ASCII_8BIT) + v.gsub!(/(?!%\h\h|[!$-&(-;=?-_a-~])./n){'%%%02X' % $&.ord} + v.force_encoding(Encoding::US_ASCII) + @query = v end # @@ -943,27 +912,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L912 # # check the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT # - def check_fragment(v) - return v unless v - - if v && v != '' && parser.regexp[:FRAGMENT] !~ v - raise InvalidComponentError, - "bad component(expected fragment component): #{v}" - end - - return true - end - private :check_fragment - - # protected setter for the fragment component +v+ - # - # see also URI::Generic.fragment= - # - def set_fragment(v) - @fragment = v - end - protected :set_fragment - # # == Args # @@ -975,8 +923,6 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L923 # public setter for the fragment component +v+. # (with validation) # - # see also URI::Generic.check_fragment - # # == Usage # # require 'uri' @@ -988,9 +934,16 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L934 # #=> #<URI::HTTP:0x000000007a81f8 URL:http://my.example.com/?id=25#time=1305212086> # def fragment=(v) - check_fragment(v) - set_fragment(v) - v + return @fragment = nil unless v + + x = v.to_str + v = x.dup if x.equal? v + v.encode!(Encoding::UTF_8) rescue nil + v.delete!("\t\r\n") + v.force_encoding(Encoding::ASCII_8BIT) + v.gsub!(/(?!%\h\h|[!-~])./n){'%%%02X' % $&.ord} + v.force_encoding(Encoding::US_ASCII) + @fragment = v end # @@ -1160,12 +1113,12 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1113 # RFC2396, Section 5.2, 2) if (rel.path.nil? || rel.path.empty?) && !authority && !rel.query - base.set_fragment(rel.fragment) if rel.fragment + base.fragment=(rel.fragment) if rel.fragment return base end - base.set_query(nil) - base.set_fragment(nil) + base.query = nil + base.fragment=(nil) # RFC2396, Section 5.2, 4) if !authority @@ -1179,8 +1132,8 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1132 base.set_userinfo(rel.userinfo) if rel.userinfo base.set_host(rel.host) if rel.host base.set_port(rel.port) if rel.port - base.set_query(rel.query) if rel.query - base.set_fragment(rel.fragment) if rel.fragment + base.query = rel.query if rel.query + base.fragment=(rel.fragment) if rel.fragment return base end # merge @@ -1287,11 +1240,11 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/generic.rb#L1240 if rel.path && rel.path == oth.path rel.set_path('') - rel.set_query(nil) if rel.query == oth.query + rel.query = nil if rel.query == oth.query return rel, rel elsif rel.opaque && rel.opaque == oth.opaque rel.set_opaque('') - rel.set_query(nil) if rel.query == oth.query + rel.query = nil if rel.query == oth.query return rel, rel end Index: test/uri/test_generic.rb =================================================================== --- test/uri/test_generic.rb (revision 46679) +++ test/uri/test_generic.rb (revision 46680) @@ -716,9 +716,9 @@ class URI::TestGeneric < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/uri/test_generic.rb#L716 uri = URI.parse('http://example.com') assert_raise(URI::InvalidURIError) { uri.password = 'bar' } - assert_raise(URI::InvalidComponentError) { uri.query = "foo\nbar" } + assert_equal("foo\nbar", uri.query = "foo\nbar") uri.userinfo = 'foo:bar' - assert_equal('http://foo:bar@e...', uri.to_s) + assert_equal('http://foo:bar@e...?foobar', uri.to_s) assert_raise(URI::InvalidURIError) { uri.registry = 'bar' } assert_raise(URI::InvalidURIError) { uri.opaque = 'bar' } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/