Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
with:
engine: cruby-jruby
min_version: 2.5
min_version: 2.6

inplace:
needs: ruby-versions-inplace
Expand All @@ -21,8 +21,6 @@ jobs:
- macos-latest
- windows-latest
ruby-version: ${{ fromJson(needs.ruby-versions-inplace.outputs.versions) }}
exclude:
- {runs-on: macos-latest, ruby-version: 2.5}
# include:
# - runs-on: ubuntu-latest
# ruby-version: truffleruby
Expand Down
4 changes: 2 additions & 2 deletions lib/rexml/doctype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DocType < Parent
'lt'=>EntityConst::LT,
'quot'=>EntityConst::QUOT,
"apos"=>EntityConst::APOS
}
}.freeze

# name is the name of the doctype
# external_id is the referenced DTD, if given
Expand Down Expand Up @@ -180,7 +180,7 @@ def entity( name, expanding: nil )

def add child
super(child)
@entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES
@entities = DEFAULT_ENTITIES.dup if @entities == DEFAULT_ENTITIES
@entities[ child.name ] = child if child.kind_of? Entity
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rexml/element.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require_relative "parent"
require_relative "namespace"
require_relative "attribute"
Expand Down Expand Up @@ -356,7 +356,7 @@ def initialize( arg = UNDEFINED, parent=nil, context=nil )
# e.inspect # => "<foo bar='0' baz='1'> ... </>"
#
def inspect
rv = "<#@expanded_name"
rv = +"<#@expanded_name"

@attributes.each_attribute do |attr|
rv << " "
Expand Down Expand Up @@ -623,7 +623,7 @@ def namespace(prefix=nil)
prefix = (prefix == '') ? 'xmlns' : prefix.delete_prefix("xmlns:")
ns = namespaces[prefix]

ns = '' if ns.nil? and prefix == 'xmlns'
ns = +'' if ns.nil? and prefix == 'xmlns'
ns
end

Expand Down
14 changes: 7 additions & 7 deletions lib/rexml/entity.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
require 'set'
require_relative 'child'
require_relative 'parseexception'
Expand Down Expand Up @@ -127,7 +127,7 @@ def write out, indent=-1

# Returns this entity as a string. See write().
def to_s
rv = ''
rv = +''
write rv
rv
end
Expand All @@ -138,14 +138,14 @@ def to_s
# CAUTION: these entities does not have parent and document
module EntityConst
# +>+
GT = Entity.new( 'gt', '>' )
GT = Entity.new( 'gt', '>' ).freeze
# +<+
LT = Entity.new( 'lt', '<' )
LT = Entity.new( 'lt', '<' ).freeze
# +&+
AMP = Entity.new( 'amp', '&' )
AMP = Entity.new( 'amp', '&' ).freeze
# +"+
QUOT = Entity.new( 'quot', '"' )
QUOT = Entity.new( 'quot', '"' ).freeze
# +'+
APOS = Entity.new( 'apos', "'" )
APOS = Entity.new( 'apos', "'" ).freeze
end
end
15 changes: 4 additions & 11 deletions lib/rexml/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module REXML
# Therefore, in XML, "local-name()" is identical (and actually becomes)
# "local_name()"
class FunctionsClass
@@available_functions = {}

def initialize
@context = nil
@namespace_context = {}
Expand All @@ -24,14 +22,7 @@ def initialize
:context=,
:get_namespace,
:send,
]
class << self
def method_added(name)
unless INTERNAL_METHODS.include?(name)
@@available_functions[name] = true
end
end
end
].freeze

def namespace_context=(x) ; @namespace_context=x ; end
def variables=(x) ; @variables=x ; end
Expand Down Expand Up @@ -422,7 +413,9 @@ def round( number )
end

def send(name, *args)
if @@available_functions[name.to_sym]
name = name.to_sym
if self.class.method_defined?(name, false) and
!INTERNAL_METHODS.include?(name)
super
else
# TODO: Maybe, this is not XPath spec behavior.
Expand Down
11 changes: 6 additions & 5 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ class BaseParser
EREFERENCE = /&(?!#{NAME};)/

DEFAULT_ENTITIES = {
'gt' => [/&gt;/, '&gt;', '>', />/],
'lt' => [/&lt;/, '&lt;', '<', /</],
'quot' => [/&quot;/, '&quot;', '"', /"/],
"apos" => [/&apos;/, "&apos;", "'", /'/]
}
'gt' => [/&gt;/, '&gt;', '>', />/].freeze,
'lt' => [/&lt;/, '&lt;', '<', /</].freeze,
'quot' => [/&quot;/, '&quot;', '"', /"/].freeze,
"apos" => [/&apos;/, "&apos;", "'", /'/].freeze
}.freeze

module Private
PEREFERENCE_PATTERN = /#{PEREFERENCE}/um
Expand All @@ -157,6 +157,7 @@ module Private
default_entities.each do |term|
DEFAULT_ENTITIES_PATTERNS[term] = /&#{term};/
end
DEFAULT_ENTITIES_PATTERNS.freeze
XML_PREFIXED_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
EXTERNAL_ID_PUBLIC_PATTERN = /\s+#{PUBIDLITERAL}\s+#{SYSTEMLITERAL}/um
EXTERNAL_ID_SYSTEM_PATTERN = /\s+#{SYSTEMLITERAL}/um
Expand Down
12 changes: 6 additions & 6 deletions lib/rexml/security.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# frozen_string_literal: false
module REXML
module Security
@@entity_expansion_limit = 10_000
@entity_expansion_limit = 10_000

# Set the entity expansion limit. By default the limit is set to 10000.
def self.entity_expansion_limit=( val )
@@entity_expansion_limit = val
@entity_expansion_limit = val
end

# Get the entity expansion limit. By default the limit is set to 10000.
def self.entity_expansion_limit
@@entity_expansion_limit
@entity_expansion_limit
end

@@entity_expansion_text_limit = 10_240
@entity_expansion_text_limit = 10_240

# Set the entity expansion limit. By default the limit is set to 10240.
def self.entity_expansion_text_limit=( val )
@@entity_expansion_text_limit = val
@entity_expansion_text_limit = val
end

# Get the entity expansion limit. By default the limit is set to 10240.
def self.entity_expansion_text_limit
@@entity_expansion_text_limit
@entity_expansion_text_limit
end
end
end
9 changes: 5 additions & 4 deletions lib/rexml/source.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding: US-ASCII
# frozen_string_literal: false
# frozen_string_literal: true

require "stringio"
require "strscan"
Expand Down Expand Up @@ -78,6 +78,7 @@ module Private
PRE_DEFINED_TERM_PATTERNS[term] = term
end
end
PRE_DEFINED_TERM_PATTERNS.freeze
end
private_constant :Private

Expand Down Expand Up @@ -227,9 +228,9 @@ def initialize(arg, block_size=500, encoding=nil)
@pending_buffer = nil

if encoding
super("", encoding)
super(+"", encoding)
else
super(@source.read(3) || "")
super(@source.read(3) || +"")
end

if !@to_utf and
Expand Down Expand Up @@ -380,7 +381,7 @@ def encoding_updated
@source.set_encoding(@encoding, @encoding)
end
@line_break = encode(">")
@pending_buffer, @scanner.string = @scanner.rest, ""
@pending_buffer, @scanner.string = @scanner.rest, +""
@pending_buffer.force_encoding(@encoding)
super
end
Expand Down
12 changes: 6 additions & 6 deletions lib/rexml/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ module REXML
class Text < Child
include Comparable
# The order in which the substitutions occur
SPECIALS = [ /&(?!#?[\w-]+;)/u, /</u, />/u, /"/u, /'/u, /\r/u ]
SUBSTITUTES = ['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#13;']
SPECIALS = [ /&(?!#?[\w-]+;)/u, /</u, />/u, /"/u, /'/u, /\r/u ].freeze
SUBSTITUTES = ['&amp;', '&lt;', '&gt;', '&quot;', '&apos;', '&#13;'].freeze
# Characters which are substituted in written strings
SLAICEPS = [ '<', '>', '"', "'", '&' ]
SETUTITSBUS = [ /&lt;/u, /&gt;/u, /&quot;/u, /&apos;/u, /&amp;/u ]
SLAICEPS = [ '<', '>', '"', "'", '&' ].freeze
SETUTITSBUS = [ /&lt;/u, /&gt;/u, /&quot;/u, /&apos;/u, /&amp;/u ].freeze

# If +raw+ is true, then REXML leaves the value alone
attr_accessor :raw
Expand All @@ -27,7 +27,7 @@ class Text < Child
(0x20..0xD7FF),
(0xE000..0xFFFD),
(0x10000..0x10FFFF)
]
].freeze

VALID_XML_CHARS = Regexp.new('^['+
VALID_CHAR.map { |item|
Expand All @@ -38,7 +38,7 @@ class Text < Child
[item.first, '-'.ord, item.last].pack('UUU').force_encoding('utf-8')
end
}.join +
']*$')
']*$').freeze

# Constructor
# +arg+ if a String, the content is set to the String. If a Text,
Expand Down
4 changes: 2 additions & 2 deletions lib/rexml/xmldecl.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true

require_relative 'encoding'
require_relative 'source'
Expand Down Expand Up @@ -117,7 +117,7 @@ def content(enc)
quote = "'"
end

rv = "version=#{quote}#{@version}#{quote}"
rv = +"version=#{quote}#{@version}#{quote}"
if @writeencoding or enc !~ /\Autf-8\z/i
rv << " encoding=#{quote}#{enc}#{quote}"
end
Expand Down
16 changes: 8 additions & 8 deletions lib/rexml/xmltokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ module XMLTokens
"\\u0300-\\u036F",
"\\u203F-\\u2040",
]
NAME_START_CHAR = "[#{name_start_chars.join('')}]"
NAME_CHAR = "[#{name_chars.join('')}]"
NAME_START_CHAR = "[#{name_start_chars.join('')}]".freeze
NAME_CHAR = "[#{name_chars.join('')}]".freeze
NAMECHAR = NAME_CHAR # deprecated. Use NAME_CHAR instead.

# From http://www.w3.org/TR/xml-names11/#NT-NCName
Expand All @@ -70,13 +70,13 @@ module XMLTokens
#
# [5] NCNameChar ::= NameChar - ':'
ncname_chars = name_chars - [":"]
NCNAME_STR = "[#{ncname_start_chars.join('')}][#{ncname_chars.join('')}]*"
NAME_STR = "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"
NCNAME_STR = "[#{ncname_start_chars.join('')}][#{ncname_chars.join('')}]*".freeze
NAME_STR = "(?:#{NCNAME_STR}:)?#{NCNAME_STR}".freeze

NAME = "(#{NAME_START_CHAR}#{NAME_CHAR}*)"
NMTOKEN = "(?:#{NAME_CHAR})+"
NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)"
NAME = "(#{NAME_START_CHAR}#{NAME_CHAR}*)".freeze
NMTOKEN = "(?:#{NAME_CHAR})+".freeze
NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*".freeze
REFERENCE = "(?:&#{NAME};|&#\\d+;|&#x[0-9a-fA-F]+;)".freeze

#REFERENCE = "(?:#{ENTITYREF}|#{CHARREF})"
#ENTITYREF = "&#{NAME};"
Expand Down
2 changes: 1 addition & 1 deletion rexml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ Gem::Specification.new do |spec|
spec.rdoc_options.concat(["--main", "README.md"])
spec.extra_rdoc_files = rdoc_files

spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = '>= 2.6.0'
end
Loading