Mangled End of Lines In Text Via XML

Hello,

I have run into a hitch where the XML returned by my actions contains
mangled EOLs.

I have a Project model that has a description attribute. In the
browser this is edited with a text area. Let’s say the user types
this (between the dashed lines):


This is line 1.
This is line 2.

This is line 4.

This is passed through to the MySQL database and stored in a field of
datatype TEXT.

When I view the project in a browser the description looks exactly as
it was entered.

When I look at the XML representation (by hitting the URL with curl),
the XML looks fine in the terminal (Terminal.app).

But when I view that XML in a text editor (vim) I see the EOLs are
inconsistent with extraneous carriage returns:


This is line 1.^M
This is line 2.^M
^M
This is line 4.

I am using an rxml template to generate the XML. The relevant part
of the template looks like this:

xml.project do
xml.description project.description
end

Is this a character encoding problem? If so, what’s the best way to
track down the point where things go awry?

The ugly workaround is to remove all the carriage returns in the
generated XML like this:

xml.description project.description.gsub(/\r/, ‘’)

…but that doesn’t solve the problem; it only addresses one
manifestation of symptoms.

I’d greatly appreciate any help solving this properly.

Thanks in advance,
Andy S.


http://airbladesoftware.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs