ruby / ruby/rexml

How to not escape ampersand in the attribute of an element?

Open
#35 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
182
Forks
99
Avg merge
2d 23h
Merged PRs (30d)
8

Description

Hi!

I am trying to create an element with attribute that looks like:

<MyElement
    myAttribute = "Hello&#10;World">
</MyElement>

which I am doing the the following code:

my_attribute = REXML::Text.new('Hello&#10;World')

my_element = REXML::Element.new('MyElement')
my_element.attributes['myAttribute'] = my_attribute

my_element.to_s

and I get Hello&amp;amp;#10;World in the attribute. I also tried using the raw flag for the Text and the { :raw => :all } context for the Element but that removes only a single amp;.

Am I missing something? How can I get to my desired output?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the REXML::Text.new call and the Element attribute serialization shown in the issue, including the raw flag and element context behavior. Trace how the attribute value is escaped and compare the result with the requested Hello World output; done means the intended serialization behavior is established and covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.