ruby-changes:54254
From: kou <ko1@a...>
Date: Thu, 20 Dec 2018 13:57:28 +0900 (JST)
Subject: [ruby-changes:54254] kou:r66458 (trunk): rexml: upgrade to 3.1.8
kou 2018-12-20 11:49:10 +0900 (Thu, 20 Dec 2018) New Revision: 66458 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66458 Log: rexml: upgrade to 3.1.8 See https://github.com/ruby/rexml/blob/master/NEWS.md for change summary. Changes for spec/ has been reported: https://github.com/ruby/spec/pull/639 Added directories: trunk/test/rexml/formatter/ Added files: trunk/test/rexml/formatter/test_default.rb trunk/test/rexml/parse/test_element.rb trunk/test/rexml/parse/test_processing_instruction.rb trunk/test/rexml/test_attribute.rb trunk/test/rexml/test_instruction.rb Modified files: trunk/NEWS trunk/lib/rexml/doctype.rb trunk/lib/rexml/formatters/default.rb trunk/lib/rexml/functions.rb trunk/lib/rexml/instruction.rb trunk/lib/rexml/namespace.rb trunk/lib/rexml/parsers/baseparser.rb trunk/lib/rexml/rexml.gemspec trunk/lib/rexml/rexml.rb trunk/lib/rexml/source.rb trunk/lib/rexml/text.rb trunk/lib/rexml/xmldecl.rb trunk/spec/ruby/library/rexml/attribute/inspect_spec.rb trunk/test/rexml/data/t75.xml trunk/test/rexml/parser/test_tree.rb trunk/test/rexml/parser/test_ultra_light.rb trunk/test/rexml/test_core.rb trunk/test/rexml/test_doctype.rb trunk/test/rexml/test_stream.rb trunk/test/rexml/test_text.rb trunk/test/rexml/test_xml_declaration.rb Index: test/rexml/formatter/test_default.rb =================================================================== --- test/rexml/formatter/test_default.rb (nonexistent) +++ test/rexml/formatter/test_default.rb (revision 66458) @@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/test/rexml/formatter/test_default.rb#L1 +require_relative "../rexml_test_utils" + +module REXMLTests + class DefaultFormatterTest < Test::Unit::TestCase + def format(node) + formatter = REXML::Formatters::Default.new + output = "" + formatter.write(node, output) + output + end + + class InstructionTest < self + def test_content_nil + instruction = REXML::Instruction.new("target") + assert_equal("<?target?>", format(instruction)) + end + end + end +end Property changes on: test/rexml/formatter/test_default.rb ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: lib/rexml/formatters/default.rb =================================================================== --- lib/rexml/formatters/default.rb (revision 66457) +++ lib/rexml/formatters/default.rb (revision 66458) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/formatters/default.rb#L1 # frozen_string_literal: false + module REXML module Formatters class Default @@ -101,11 +102,14 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/formatters/default.rb#L102 end def write_instruction( node, output ) - output << Instruction::START.sub(/\\/u, '') + output << Instruction::START output << node.target - output << ' ' - output << node.content - output << Instruction::STOP.sub(/\\/u, '') + content = node.content + if content + output << ' ' + output << content + end + output << Instruction::STOP end end end Index: lib/rexml/rexml.rb =================================================================== --- lib/rexml/rexml.rb (revision 66457) +++ lib/rexml/rexml.rb (revision 66458) @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/rexml.rb#L1 -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- # frozen_string_literal: false # REXML is an XML toolkit for Ruby[http://www.ruby-lang.org], in Ruby. # @@ -24,8 +24,8 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/rexml.rb#L24 module REXML COPYRIGHT = "Copyright 息 2001-2008 Sean Russell <ser@g...>" DATE = "2008/019" - VERSION = "3.1.7.3" - REVISION = %w$Revision$[1] || '' + VERSION = "3.1.8" + REVISION = "" Copyright = COPYRIGHT Version = VERSION Index: lib/rexml/namespace.rb =================================================================== --- lib/rexml/namespace.rb (revision 66457) +++ lib/rexml/namespace.rb (revision 66458) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/namespace.rb#L1 # frozen_string_literal: false + require_relative 'xmltokens' module REXML @@ -14,14 +15,24 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/namespace.rb#L15 # Sets the name and the expanded name def name=( name ) @expanded_name = name - name =~ NAMESPLIT - if $1 - @prefix = $1 + case name + when NAMESPLIT + if $1 + @prefix = $1 + else + @prefix = "" + @namespace = "" + end + @name = $2 + when "" + @prefix = nil + @namespace = nil + @name = nil else - @prefix = "" - @namespace = "" + message = "name must be \#{PREFIX}:\#{LOCAL_NAME} or \#{LOCAL_NAME}: " + message += "<#{name.inspect}>" + raise ArgumentError, message end - @name = $2 end # Compares names optionally WITH namespaces Index: lib/rexml/source.rb =================================================================== --- lib/rexml/source.rb (revision 66457) +++ lib/rexml/source.rb (revision 66458) @@ -254,6 +254,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/source.rb#L254 end rescue end + @er_source.seek(pos) rescue IOError pos = -1 line = -1 Index: lib/rexml/rexml.gemspec =================================================================== --- lib/rexml/rexml.gemspec (revision 66457) +++ lib/rexml/rexml.gemspec (revision 66458) @@ -16,23 +16,65 @@ Gem::Specification.new do |spec| https://github.com/ruby/ruby/blob/trunk/lib/rexml/rexml.gemspec#L16 spec.homepage = "https://github.com/ruby/rexml" spec.license = "BSD-2-Clause" - spec.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", - "bin/console", "bin/setup", "lib/rexml/attlistdecl.rb", "lib/rexml/attribute.rb", "lib/rexml/cdata.rb", - "lib/rexml/child.rb", "lib/rexml/comment.rb", "lib/rexml/doctype.rb", "lib/rexml/document.rb", - "lib/rexml/dtd/attlistdecl.rb", "lib/rexml/dtd/dtd.rb", "lib/rexml/dtd/elementdecl.rb", - "lib/rexml/dtd/entitydecl.rb", "lib/rexml/dtd/notationdecl.rb", "lib/rexml/element.rb", - "lib/rexml/encoding.rb", "lib/rexml/entity.rb", "lib/rexml/formatters/default.rb", - "lib/rexml/formatters/pretty.rb", "lib/rexml/formatters/transitive.rb", "lib/rexml/functions.rb", - "lib/rexml/instruction.rb", "lib/rexml/light/node.rb", "lib/rexml/namespace.rb", "lib/rexml/node.rb", - "lib/rexml/output.rb", "lib/rexml/parent.rb", "lib/rexml/parseexception.rb", "lib/rexml/parsers/baseparser.rb", - "lib/rexml/parsers/lightparser.rb", "lib/rexml/parsers/pullparser.rb", "lib/rexml/parsers/sax2parser.rb", - "lib/rexml/parsers/streamparser.rb", "lib/rexml/parsers/treeparser.rb", - "lib/rexml/parsers/ultralightparser.rb", "lib/rexml/parsers/xpathparser.rb", "lib/rexml/quickpath.rb", - "lib/rexml/rexml.rb", "lib/rexml/sax2listener.rb", "lib/rexml/security.rb", "lib/rexml/source.rb", - "lib/rexml/streamlistener.rb", "lib/rexml/syncenumerator.rb", "lib/rexml/text.rb", - "lib/rexml/undefinednamespaceexception.rb", "lib/rexml/validation/relaxng.rb", - "lib/rexml/validation/validation.rb", "lib/rexml/validation/validationexception.rb", "lib/rexml/xmldecl.rb", - "lib/rexml/xmltokens.rb", "lib/rexml/xpath.rb", "lib/rexml/xpath_parser.rb", "rexml.gemspec"] + spec.files = [ + ".gitignore", + ".travis.yml", + "Gemfile", + "LICENSE.txt", + "README.md", + "Rakefile", + "lib/rexml/attlistdecl.rb", + "lib/rexml/attribute.rb", + "lib/rexml/cdata.rb", + "lib/rexml/child.rb", + "lib/rexml/comment.rb", + "lib/rexml/doctype.rb", + "lib/rexml/document.rb", + "lib/rexml/dtd/attlistdecl.rb", + "lib/rexml/dtd/dtd.rb", + "lib/rexml/dtd/elementdecl.rb", + "lib/rexml/dtd/entitydecl.rb", + "lib/rexml/dtd/notationdecl.rb", + "lib/rexml/element.rb", + "lib/rexml/encoding.rb", + "lib/rexml/entity.rb", + "lib/rexml/formatters/default.rb", + "lib/rexml/formatters/pretty.rb", + "lib/rexml/formatters/transitive.rb", + "lib/rexml/functions.rb", + "lib/rexml/instruction.rb", + "lib/rexml/light/node.rb", + "lib/rexml/namespace.rb", + "lib/rexml/node.rb", + "lib/rexml/output.rb", + "lib/rexml/parent.rb", + "lib/rexml/parseexception.rb", + "lib/rexml/parsers/baseparser.rb", + "lib/rexml/parsers/lightparser.rb", + "lib/rexml/parsers/pullparser.rb", + "lib/rexml/parsers/sax2parser.rb", + "lib/rexml/parsers/streamparser.rb", + "lib/rexml/parsers/treeparser.rb", + "lib/rexml/parsers/ultralightparser.rb", + "lib/rexml/parsers/xpathparser.rb", + "lib/rexml/quickpath.rb", + "lib/rexml/rexml.rb", + "lib/rexml/sax2listener.rb", + "lib/rexml/security.rb", + "lib/rexml/source.rb", + "lib/rexml/streamlistener.rb", + "lib/rexml/syncenumerator.rb", + "lib/rexml/text.rb", + "lib/rexml/undefinednamespaceexception.rb", + "lib/rexml/validation/relaxng.rb", + "lib/rexml/validation/validation.rb", + "lib/rexml/validation/validationexception.rb", + "lib/rexml/xmldecl.rb", + "lib/rexml/xmltokens.rb", + "lib/rexml/xpath.rb", + "lib/rexml/xpath_parser.rb", + "rexml.gemspec", + ] spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] Index: lib/rexml/instruction.rb =================================================================== --- lib/rexml/instruction.rb (revision 66457) +++ lib/rexml/instruction.rb (revision 66458) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/instruction.rb#L1 # frozen_string_literal: false + require_relative "child" require_relative "source" @@ -6,8 +7,8 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/instruction.rb#L7 # Represents an XML Instruction; IE, <? ... ?> # TODO: Add parent arg (3rd arg) to constructor class Instruction < Child - START = '<\?' - STOP = '\?>' + START = "<?" + STOP = "?>" # target is the "name" of the Instruction; IE, the "tag" in <?tag ...?> # content is everything else. @@ -17,20 +18,25 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/instruction.rb#L18 # @param target can be one of a number of things. If String, then # the target of this instruction is set to this. If an Instruction, # then the Instruction is shallowly cloned (target and content are - # copied). If a Source, then the source is scanned and parsed for - # an Instruction declaration. + # copied). # @param content Must be either a String, or a Parent. Can only # be a Parent if the target argument is a Source. Otherwise, this # String is set as the content of this instruction. def initialize(target, content=nil) - if target.kind_of? String + case target + when String super() @target = target @content = content - elsif target.kind_of? Instruction + when Instruction super(content) @target = target.target @content = target.content + else + message = + "processing instruction target must be String or REXML::Instruction: " + message << "<#{target.inspect}>" + raise ArgumentError, message end @content.strip! if @content end @@ -45,11 +51,13 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/instruction.rb#L51 def write writer, indent=-1, transitive=false, ie_hack=false Kernel.warn( "#{self.class.name}.write is deprecated", uplevel: 1) indent(writer, indent) - writer << START.sub(/\\/u, '') + writer << START writer << @target - writer << ' ' - writer << @content - writer << STOP.sub(/\\/u, '') + if @content + writer << ' ' + writer << @content + end + writer << STOP end # @return true if other is an Instruction, and the content and target Index: lib/rexml/text.rb =================================================================== --- lib/rexml/text.rb (revision 66457) +++ lib/rexml/text.rb (revision 66458) @@ -96,27 +96,28 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/text.rb#L96 @raw = false @parent = nil + @entity_filter = nil if parent super( parent ) @raw = parent.raw end - @raw = raw unless raw.nil? - @entity_filter = entity_filter - clear_cache - if arg.kind_of? String @string = arg.dup - @string.squeeze!(" \n\t") unless respect_whitespace elsif arg.kind_of? Text - @string = arg.to_s + @string = arg.instance_variable_get(:@string).dup @raw = arg.raw + @entity_filter = arg.instance_variable_get(:@entity_filter) elsif raise "Illegal argument of type #{arg.type} for Text constructor (#{arg})" end - @string.gsub!( /\r\n?/, "\n" ) + @string.squeeze!(" \n\t") unless respect_whitespace + @string.gsub!(/\r\n?/, "\n") + @raw = raw unless raw.nil? + @entity_filter = entity_filter if entity_filter + clear_cache Text.check(@string, illegal, doctype) if @raw end @@ -181,7 +182,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/text.rb#L182 def clone - return Text.new(self) + return Text.new(self, true) end @@ -226,9 +227,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/text.rb#L227 # u.to_s #-> "sean russell" def to_s return @string if @raw - return @normalized if @normalized - - @normalized = Text::normalize( @string, doctype, @entity_filter ) + @normalized ||= Text::normalize( @string, doctype, @entity_filter ) end def inspect @@ -249,8 +248,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/text.rb#L248 # u = Text.new( "sean russell", false, nil, true ) # u.value #-> "sean russell" def value - return @unnormalized if @unnormalized - @unnormalized = Text::unnormalize( @string, doctype ) + @unnormalized ||= Text::unnormalize( @string, doctype ) end # Sets the contents of this text node. This expects the text to be @@ -266,16 +264,16 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/text.rb#L264 @raw = false end - def wrap(string, width, addnewline=false) - # Recursively wrap string at width. - return string if string.length <= width - place = string.rindex(' ', width) # Position in string with last ' ' before cutoff - if addnewline then - return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width) - else - return string[0,place] + "\n" + wrap(string[place+1..-1], width) - end - end + def wrap(string, width, addnewline=false) + # Recursively wrap string at width. + return string if string.length <= width + place = string.rindex(' ', width) # Position in string with last ' ' before cutoff + if addnewline then + return "\n" + string[0,place] + "\n" + wrap(string[place+1..-1], width) + else + return string[0,place] + "\n" + wrap(string[place+1..-1], width) + end + end def indent_text(string, level=1, style="\t", indentfirstline=true) return string if level < 0 Index: lib/rexml/xmldecl.rb =================================================================== --- lib/rexml/xmldecl.rb (revision 66457) +++ lib/rexml/xmldecl.rb (revision 66458) @@ -1,4 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/lib/rexml/xmldecl.rb#L1 # frozen_string_literal: false + require_relative 'encoding' require_relative 'source' @@ -7,11 +8,11 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/xmldecl.rb#L8 class XMLDecl < Child include Encoding - DEFAULT_VERSION = "1.0"; - DEFAULT_ENCODING = "UTF-8"; - DEFAULT_STANDALONE = "no"; - START = '<\?xml'; - STOP = '\?>'; + DEFAULT_VERSION = "1.0" + DEFAULT_ENCODING = "UTF-8" + DEFAULT_STANDALONE = "no" + START = "<?xml" + STOP = "?>" attr_accessor :version, :standalone attr_reader :writeencoding, :writethis @@ -46,9 +47,9 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/xmldecl.rb#L47 # Ignored def write(writer, indent=-1, transitive=false, ie_hack=false) return nil unless @writethis or writer.kind_of? Output - writer << START.sub(/\\/u, '') + writer << START writer << " #{content encoding}" - writer << STOP.sub(/\\/u, '') + writer << STOP end def ==( other ) @@ -102,14 +103,26 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/xmldecl.rb#L103 end def inspect - START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '') + "#{START} ... #{STOP}" end private def content(enc) - rv = "version='#@version'" - rv << " encoding='#{enc}'" if @writeencoding || enc !~ /\Autf-8\z/i - rv << " standalone='#@standalone'" if @standalone + context = nil + context = parent.context if parent + if context and context[:prologue_quote] == :quote + quote = "\"" + else + quote = "'" + end + + rv = "version=#{quote}#{@version}#{quote}" + if @writeencoding or enc !~ /\Autf-8\z/i + rv << " encoding=#{quote}#{enc}#{quote}" + end + if @standalone + rv << " standalone=#{quote}#{@standalone}#{quote}" + end rv end end Index: lib/rexml/doctype.rb =================================================================== --- lib/rexml/doctype.rb (revision 66457) +++ lib/rexml/doctype.rb (revision 66458) @@ -108,13 +108,19 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/doctype.rb#L108 # Ignored def write( output, indent=0, transitive=false, ie_hack=false ) f = REXML::Formatters::Default.new + c = context + if c and c[:prologue_quote] == :apostrophe + quote = "'" + else + quote = "\"" + end indent( output, indent ) output << START output << ' ' output << @name - output << " #@external_id" if @external_id - output << " #{@long_name.inspect}" if @long_name - output << " #{@uri.inspect}" if @uri + output << " #{@external_id}" if @external_id + output << " #{quote}#{@long_name}#{quote}" if @long_name + output << " #{quote}#{@uri}#{quote}" if @uri unless @children.empty? output << ' [' @children.each { |child| @@ -127,7 +133,11 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/doctype.rb#L133 end def context - @parent.context + if @parent + @parent.context + else + nil + end end def entity( name ) @@ -249,9 +259,16 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/doctype.rb#L259 end def to_s + c = nil + c = parent.context if parent + if c and c[:prologue_quote] == :apostrophe + quote = "'" + else + quote = "\"" + end notation = "<!NOTATION #{@name} #{@middle}" - notation << " #{@public.inspect}" if @public - notation << " #{@system.inspect}" if @system + notation << " #{quote}#{@public}#{quote}" if @public + notation << " #{quote}#{@system}#{quote}" if @system notation << ">" notation end Index: lib/rexml/functions.rb =================================================================== --- lib/rexml/functions.rb (revision 66457) +++ lib/rexml/functions.rb (revision 66458) @@ -423,7 +423,7 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/functions.rb#L423 number = number(number) begin neg = number.negative? - number = number.abs.round(half: :up) + number = number.abs.round neg ? -number : number rescue FloatDomainError number Index: lib/rexml/parsers/baseparser.rb =================================================================== --- lib/rexml/parsers/baseparser.rb (revision 66457) +++ lib/rexml/parsers/baseparser.rb (revision 66458) @@ -3,6 +3,7 @@ require_relative '../parseexception' https://github.com/ruby/ruby/blob/trunk/lib/rexml/parsers/baseparser.rb#L3 require_relative '../undefinednamespaceexception' require_relative '../source' require 'set' +require "strscan" module REXML module Parsers @@ -32,9 +33,9 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/parsers/baseparser.rb#L33 COMBININGCHAR = '' # TODO EXTENDER = '' # TODO - NCNAME_STR= "[#{LETTER}_:][-[:alnum:]._:#{COMBININGCHAR}#{EXTENDER}]*" - NAME_STR= "(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})" - UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}" + NCNAME_STR= "[#{LETTER}_][-[:alnum:]._#{COM (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/