Skip to content

Commit

Permalink
test: Fix invalid XML with spaces before the XML declaration (#115)
Browse files Browse the repository at this point in the history
## Why?
XML declaration allowed only at the start of the document.

https://www.w3.org/TR/2006/REC-xml11-20060816/#document

```
[1]   document   ::=   ( prolog element Misc* ) - ( Char* RestrictedChar Char* ) 
```

It doesn't have `S*` before `prolog`.

https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-prolog

```
[22]   prolog   ::=   	XMLDecl Misc* (doctypedecl Misc*)?
```

It doesn't have `S*` before `XMLdecl`.

https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-XMLDecl

```
[23]   XMLDecl  ::=   '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
```

It doesn't have `S*` before `'<?xml'`.
  • Loading branch information
naitoh committed Feb 20, 2024
1 parent 372daf1 commit fb7ba27
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion test/functions/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_normalize_space_strings
end

def test_string_nil_without_context
doc = REXML::Document.new(<<-XML)
doc = REXML::Document.new(<<~XML)
<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo bar="baz"/>
Expand Down
4 changes: 2 additions & 2 deletions test/test_contrib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_bad_doctype_Tobias

# Peter Verhage
def test_namespace_Peter
source = <<-EOF
source = <<~EOF
<?xml version="1.0"?>
<config:myprog-config xmlns:config="http://someurl/program/version">
<!-- main options -->
Expand Down Expand Up @@ -377,7 +377,7 @@ def test_various_xpath
end

def test_entities_Holden_Glova
document = <<-EOL
document = <<~EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rubynet [
<!ENTITY rbconfig.MAJOR "1">
Expand Down
12 changes: 6 additions & 6 deletions test/test_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Tester < Test::Unit::TestCase
include Helper::Fixture
include REXML
def setup
@xsa_source = <<-EOL
@xsa_source = <<~EOL
<?xml version="1.0"?>
<?xsl stylesheet="blah.xsl"?>
<!-- The first line tests the XMLDecl, the second tests PI.
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_attribute

# Bryan Murphy <murphybryanp@yahoo.com>
text = "this is a {target[@name='test']/@value} test"
source = <<-EOL
source = <<~EOL
<?xml version="1.0"?>
<doc search="#{text}"/>
EOL
Expand Down Expand Up @@ -869,7 +869,7 @@ def test_attlist_decl
assert_equal 'two', doc.root.elements[1].namespace
assert_equal 'foo', doc.root.namespace

doc = Document.new <<-EOL
doc = Document.new <<~EOL
<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "XMLSchema.dtd" [
<!ENTITY % p ''>
Expand Down Expand Up @@ -946,7 +946,7 @@ def test_processing_instruction
end

def test_oses_with_bad_EOLs
Document.new("\n\n\n<?xml version='1.0'?>\n\n\n<a/>\n\n")
Document.new("<?xml version='1.0'?>\n\n\n<a/>\n\n")
end

# Contributed (with patch to fix bug) by Kouhei
Expand All @@ -973,7 +973,7 @@ def test_0xD_in_preface
end

def test_hyphens_in_doctype
doc = REXML::Document.new <<-EOQ
doc = REXML::Document.new <<~EOQ
<?xml version="1.0"?>
<!DOCTYPE a-b-c>
<a-b-c>
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def test_null_element_name
def test_text_raw
# From the REXML tutorial
# (http://www.germane-software.com/software/rexml/test/data/tutorial.html)
doc = Document.new <<-EOL
doc = Document.new <<~EOL
<?xml version="1.0"?>
<!DOCTYPE schema SYSTEM "XMLSchema.dtd" [
<!ENTITY % s 'Sean'>
Expand Down
2 changes: 1 addition & 1 deletion test/test_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module REXMLTests
class TestDocument < Test::Unit::TestCase
def test_version_attributes_to_s
doc = REXML::Document.new(<<-eoxml)
doc = REXML::Document.new(<<~eoxml)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg id="svg2"
xmlns:sodipodi="foo"
Expand Down
4 changes: 2 additions & 2 deletions test/test_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_in_different_out
# * Given an encoded document, accessing text and attribute nodes
# should provide UTF-8 text.
def test_in_different_access
doc = Document.new <<-EOL
doc = Document.new <<~EOL
<?xml version='1.0' encoding='ISO-8859-1'?>
<a a="\xFF">\xFF</a>
EOL
Expand All @@ -79,7 +79,7 @@ def test_in_different_access


def test_ticket_89
doc = Document.new <<-EOL
doc = Document.new <<~EOL
<?xml version="1.0" encoding="CP-1252" ?>
<xml><foo></foo></xml>
EOL
Expand Down
4 changes: 2 additions & 2 deletions test/test_sax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def doctype(name, pub_sys, long_name, uri)
# test simple non-entity doctype in sax listener
# submitted by Jeff Barczewski
def test_simple_doctype_listener
xml = <<-END
xml = <<~END
<?xml version="1.0"?>
<!DOCTYPE greeting PUBLIC "Hello Greeting DTD" "http://foo/hello.dtd">
<greeting>Hello, world!</greeting>
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_simple_doctype_listener
# test doctype with missing name, should throw ParseException
# submitted by Jeff Barczewseki
def test_doctype_with_mising_name_throws_exception
xml = <<-END
xml = <<~END
<?xml version="1.0"?>
<!DOCTYPE >
<greeting>Hello, world!</greeting>
Expand Down
Loading

0 comments on commit fb7ba27

Please sign in to comment.