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
2 changes: 1 addition & 1 deletion lib/rexml/cdata.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 "text"

module REXML
Expand Down
2 changes: 1 addition & 1 deletion lib/rexml/comment.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 "child"

module REXML
Expand Down
8 changes: 4 additions & 4 deletions lib/rexml/doctype.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 "parseexception"
require_relative "namespace"
Expand Down 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 @@ -183,7 +183,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 Expand Up @@ -288,7 +288,7 @@ def initialize name, middle, pub, sys

def to_s
context = parent&.context
notation = "<!NOTATION #{@name}"
notation = +"<!NOTATION #{@name}"
reference_writer = ReferenceWriter.new(@middle, @public, @system, context)
reference_writer.write(notation)
notation << ">"
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 @@ -1524,7 +1524,7 @@ def _namespace_internal(namespaces = _calculate_namespaces) # :nodoc:
def _namespace_lookup_internal(prefix, namespaces = _calculate_namespaces) # :nodoc:
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 # :nodoc:
@@available_functions = {}

def initialize
@context = nil
@namespace_context = {}
Expand All @@ -26,14 +24,7 @@ def initialize
:send,
:compare_language,
:string_value,
]
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 @@ -415,7 +406,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
6 changes: 3 additions & 3 deletions lib/rexml/instruction.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 "child"
require_relative "source"
Expand Down Expand Up @@ -34,8 +34,8 @@ def initialize(target, content=nil)
@content = target.content
else
message =
"processing instruction target must be String or REXML::Instruction: "
message << "<#{target.inspect}>"
"processing instruction target must be String or REXML::Instruction: " \
"<#{target.inspect}>"
raise ArgumentError, message
end
@content.strip! if @content
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
3 changes: 2 additions & 1 deletion test/functions/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_available_functions
name namespace-uri normalize-space not number position round starts-with
string string-length substring substring-after substring-before sum translate true
]
methods = REXML::FunctionsClass.class_variable_get(:@@available_functions).keys.sort
methods = REXML::FunctionsClass.instance_methods(false) -
REXML::FunctionsClass::INTERNAL_METHODS
assert_equal expected_functions, methods.map { |m| m.to_s.tr('_', '-') }.sort
end

Expand Down
Loading
Loading