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

String.encode(Encoding, :xml => :text) double encodes ampersand #1545

Closed
pepijnve opened this issue Jan 22, 2019 · 4 comments
Closed

String.encode(Encoding, :xml => :text) double encodes ampersand #1545

pepijnve opened this issue Jan 22, 2019 · 4 comments
Assignees
Milestone

Comments

@pepijnve
Copy link

Tested with 1.0-RC11.

This test passes on MRI. On Truffle it produces ±.

describe "String.encode" do
  it 'should behave like MRI' do
    expect("\u00B1".encode(Encoding::US_ASCII, :xml => :text)).to(eq("±"))
  end
end
@nirvdrum
Copy link
Collaborator

Thanks for the test. This looks like something that should be added to the Ruby Spec Suite. Unfortunately, String#encode with the xml option isn't completely implemented and we fail several other related specs, as seen in our tags file: https://github.com/oracle/truffleruby/blob/5975d2aa48ea24e560baa81abe62cffc89cb9b3c/spec/tags/core/string/encode_tags.txt

If you don't mind me asking, what's the use case? We need to implement it, regardless. I'm just curious because I don't think I've ever seen it used.

@nirvdrum nirvdrum self-assigned this Jan 22, 2019
@pepijnve
Copy link
Author

@nirvdrum see asciidoctor/asciimath#10
I'm using it as a really simple way to prepare a string for embedding in other XML content.

The input string is MathML containing various mathematical symbols which are represented as their Unicode codepoint. In order to make the final MathML string as safe and simple to use as possible I opted to XML escape anything that's outside 7-bit ASCII. String.encode was the most straightforward way to achieve that.

@nirvdrum
Copy link
Collaborator

nirvdrum commented Jan 23, 2019

@pepijnve I've fixed this issue in 5667e6c and it will ship in the next TruffleRuby release (1.0.0 RC 12). Thanks again for the detailed bug report!

@nirvdrum nirvdrum added this to the 1.0.0-rc12 milestone Jan 23, 2019
@nirvdrum
Copy link
Collaborator

nirvdrum commented Feb 5, 2019

@pepijnve TruffleRuby 1.0.0 RC 12 is now available with this bug fixed. Please try out the new release at your convenience and let me know if you run into any problems. Thanks again for filing an issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants