Skip to content

Commit

Permalink
Made sure the convert_special option works for attributes as well as …
Browse files Browse the repository at this point in the history
…element text in the SAX parser.
  • Loading branch information
ohler55 committed Oct 22, 2015
1 parent 2179ea9 commit 65f0b13
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -34,6 +34,14 @@ A fast XML parser and Object marshaller as a Ruby gem.

## Release Notes

### Future Release 2.2.3

- The convert_special option now applies to attributes as well as elements in
the SAX parser.

- The convert_special option now applies to the regualr parser as well as the
SAX parser.

### Release 2.2.2

- Fixed problem with detecting invalid special character sequences.
Expand Down
4 changes: 3 additions & 1 deletion ext/ox/sax.c
Expand Up @@ -1333,7 +1333,9 @@ read_attrs(SaxDrive dr, char c, char termc, char term2, int is_xml, int eq_req)
VALUE args[2];

args[0] = name;
ox_sax_collapse_special(dr, dr->buf.str, pos, line, col);
if (dr->options.convert_special) {
ox_sax_collapse_special(dr, dr->buf.str, pos, line, col);
}
args[1] = rb_str_new2(attr_value);
#if HAS_ENCODING_SUPPORT
if (0 != dr->encoding) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ox/version.rb
@@ -1,5 +1,5 @@

module Ox
# Current version of the module.
VERSION = '2.2.2'
VERSION = '2.2.3a1'
end
14 changes: 11 additions & 3 deletions test/sax/sax_test.rb
Expand Up @@ -396,10 +396,19 @@ def test_sax_bad_special
], AllSax, :convert_special => true)
end

def test_sax_ignore_special
parse_compare(%{<top name="&example;">&example;</top>},
[[:start_element, :top],
[:attr, :name, '&example;'],
[:text, "&example;"],
[:end_element, :top]
], AllSax, :convert_special => false)
end

def test_sax_not_special
parse_compare(%{<top name="A&amp;Z">This is &lt;some&gt; text.</top>},
[[:start_element, :top],
[:attr, :name, 'A&Z'],
[:attr, :name, 'A&amp;Z'],
[:text, "This is &lt;some&gt; text."],
[:end_element, :top]
], AllSax, :convert_special => false)
Expand All @@ -422,7 +431,7 @@ def test_sax_not_special_default
Ox::default_options = { :convert_special => false }
parse_compare(%{<top name="A&amp;Z">This is &lt;some&gt; text.</top>},
[[:start_element, :top],
[:attr, :name, 'A&Z'],
[:attr, :name, 'A&amp;Z'],
[:text, "This is &lt;some&gt; text."],
[:end_element, :top]
], AllSax)
Expand Down Expand Up @@ -922,7 +931,6 @@ def test_sax_tolerant
[:attr, :garbage, "trash"],
[:error, "Invalid Element: bad is not a valid element type for a HTML document type.", 4, 9],
[:start_element, :bad],
[:error, "Not Terminated: special character does not end with a semicolon", 4, 29],
[:attr, :attr, "some&#xthing"],
[:error, "Invalid Element: bad is not a valid element type for a HTML document type.", 5, 9],
[:start_element, :bad],
Expand Down
6 changes: 6 additions & 0 deletions test/tests.rb
Expand Up @@ -330,6 +330,12 @@ def test_escape_bad
assert(false)
end

def test_escape_ignore
xml = %{<top name="&example;">&example;</top>}
doc = Ox.load(xml, :convert_special => false)
puts doc
end

def test_escape_hex_value
xml = %{\n<top name="&lt;&#x40;test&gt;"/>\n}
doc = Ox.parse(xml)
Expand Down

0 comments on commit 65f0b13

Please sign in to comment.