Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with context raw? #43

Open
BurdetteLamar opened this issue Feb 2, 2021 · 1 comment
Open

Problem with context raw? #43

BurdetteLamar opened this issue Feb 2, 2021 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@BurdetteLamar
Copy link
Member

Running ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [i386-mingw32]

  xml_string = '<root><foo>&amp;</foo><bar>&lt;</bar><baz>&gt;</baz><bat>&quot;</bat></root>'
  d = Document.new(xml_string, {raw: ['foo', 'baz']})
  d.to_s # => "<root><foo>&amp;</foo><bar>&lt;</bar><baz>&gt;</baz><bat>&quot;</bat></root>"
  root = d.root # => <root> ... </>
  foo, bar, baz, bat = *d.root
  # Each is an Element object:
  [foo, bar, baz, bat].map {|e| e.class }.uniq # => [REXML::Element]
  # Each element is marked as raw/not-raw as appropriate:
  [foo, bar, baz, bat].map {|e| e.raw } # => [true, false, true, false]
  # The first child of each is a Text object:
  [foo, bar, baz, bat].map {|e| e.first.class }.uniq # => [REXML::Text]
  # Each text is marked as raw/not-raw as appropriate:
  [foo, bar, baz, bat].map {|e| e.first.raw } # => [true, true, true, true]

Is this correct? I expected that last result to be [true, false, true, false].

@BurdetteLamar BurdetteLamar added the question Further information is requested label Feb 2, 2021
@kou
Copy link
Member

kou commented Feb 3, 2021

raw is meaningless when parsing an XML.
Because text data in XML is always raw text (escaped text, e.g.: &amp; not &).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

2 participants