# Mangled End of Lines In Text Via XML

**URL:** <https://www.ruby-forum.com/t/mangled-end-of-lines-in-text-via-xml/113264>\
**Category:** Rails\
**Created:** [August 29, 2007, 11:42am UTC](https://www.ruby-forum.com/t/mangled-end-of-lines-in-text-via-xml/113264 "2007-08-29T11:42:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [August 29, 2007, 11:42am UTC](https://www.ruby-forum.com/t/mangled-end-of-lines-in-text-via-xml/113264/1 "2007-08-29T11:42:50Z")

</div>

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.

* * *

> **[AirBlade Software](https://airbladesoftware.com/)**
>
> Andrew Stewart of AirBlade Software.
