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

Escaped HTML characters in output #58

Open
emptyflask opened this issue Oct 1, 2019 · 5 comments
Open

Escaped HTML characters in output #58

emptyflask opened this issue Oct 1, 2019 · 5 comments
Assignees

Comments

@emptyflask
Copy link

Even with Oj.mimic_JSON set, there doesn't seem to be a way to output the non-escaped characters.

{"other_serializer": {"body":"&nbsp;<p>..."}}
{"panko_serializer": {"body":"\u0026nbsp;\u003cp\u003e..."}}

It doesn't seem to be due to the Oj::StringWriter, so perhaps this is happening at a lower level:

puts Oj::StringWriter.new.tap{|w| w.push_json '"<p>&nbsp;</p>"', "body"}.to_s
# "body":"<p>&nbsp;</p>"
@emptyflask
Copy link
Author

I don't think this matters much in practice, it seems like most clients are able to handle it.

@yosiat
Copy link
Owner

yosiat commented Jan 11, 2020

Hi @emptyflask !

Sorry for not getting in touch about this PR!

Some questions before I can dig in, I assume you serialize ActiveRecord objects:

  • Which version of Rails and Ruby are you using?
  • Which DB provider? MySQL / PostgreSQL / SQLite ?
  • What's the value stored in DB? <p>&nbsp;</p> ?

@yosiat yosiat added the bug label Jan 11, 2020
@yosiat yosiat self-assigned this Jan 11, 2020
@yosiat yosiat assigned emptyflask and unassigned yosiat Jan 11, 2020
@yosiat
Copy link
Owner

yosiat commented Mar 9, 2020

@emptyflask hi! can you give any answers to the questions I asked? I think this is a quick one to fix, just need your input here so I can reproduce it correctly.

@emptyflask
Copy link
Author

emptyflask commented Mar 9, 2020

Oh, sorry, I got buried with other stuff and forgot to respond to this.

I will have to do some testing again, but I believe this was with Rails 5.x and PostgreSQL, and &nbsp; being the text in question stored in the db.

@emptyflask
Copy link
Author

Ruby 2.6.3
Rails 6.0 (in this case I don't think it matters)

class FooSerializer < Panko::Serializer
  attributes :body
end

FooSerializer.new.serialize(Struct.new(:body).new("<p>&nbsp;</p>")).to_json
# => {"body":"\u003cp\u003e\u0026nbsp;\u003c/p\u003e"}

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