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
5 changes: 3 additions & 2 deletions lib/rexml/parsers/baseparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative '../security'
require_relative '../source'
require_relative '../text'
require_relative '../xmltokens'
require 'set'
require "strscan"

Expand Down Expand Up @@ -70,8 +71,8 @@ class BaseParser
# It's not used in REXML.
UNAME_STR= "(?:#{NCNAME_STR}:)?#{NCNAME_STR}"

NAMECHAR = '[\-\w\.:]'
NAME = "([\\w:]#{NAMECHAR}*)"
NAMECHAR = XMLTokens::NAME_CHAR
NAME = XMLTokens::NAME
NMTOKEN = "(?:#{NAMECHAR})+"
NMTOKENS = "#{NMTOKEN}(\\s+#{NMTOKEN})*"
REFERENCE = "&(?:#{NAME};|#\\d+;|#x[0-9a-fA-F]+;)"
Expand Down
7 changes: 7 additions & 0 deletions test/parse/test_document_type_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def test_valid
assert_equal("r", doctype.name)
end

def test_non_ascii
doctype = parse(<<-DOCTYPE)
<!DOCTYPE été>
DOCTYPE
assert_equal("été", doctype.name)
end

def test_garbage_plus_before_name_at_line_start
exception = assert_raise(REXML::ParseException) do
parse(<<-DOCTYPE)
Expand Down
8 changes: 8 additions & 0 deletions test/parse/test_entity_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def test_prohibited_character
invalid&name "valid-entity-value">]>
DETAIL
end

def test_non_ascii
document = REXML::Document.new(<<-XML)
<!DOCTYPE r [<!ENTITY été "summer">]>
<r>&été;</r>
XML
assert_equal("summer", document.root.text)
end
end

# https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityDef
Expand Down
5 changes: 5 additions & 0 deletions test/parse/test_notation_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def test_name
assert_equal("name", doctype.notation("name").name)
end

def test_non_ascii_name
doctype = parse("<!NOTATION été PUBLIC 'urn:public-id'>")
assert_equal("été", doctype.notation("été").name)
end

def test_no_name
exception = assert_raise(REXML::ParseException) do
parse(<<-INTERNAL_SUBSET)
Expand Down
5 changes: 5 additions & 0 deletions test/parse/test_processing_instruction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ def test_content_question
assert_equal("con?tent", document.root.children.first.content)
end

def test_non_ascii_target
document = parse("<?été content?><r/>")
assert_equal("été", document.children.first.target)
end

def test_linear_performance_gt
seq = [10000, 50000, 100000, 150000, 200000]
assert_linear_performance(seq, rehearsal: 10) do |n|
Expand Down