# Database text and '\<'

**URL:** <https://www.ruby-forum.com/t/database-text-and/116232>\
**Category:** Rails\
**Created:** [October 3, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/database-text-and/116232 "2007-10-03T17:46:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/1 "2007-10-03T17:46:58Z")

</div>

I just typed a long post with my model, controller and view file  
snippets, and lost it ☹ Here goes again:

I have a 2 postgres tables: files and lines. Files simply has an id  
and a string name. Lines has a file\_id, line\_number and line\_text. I  
have the associations set up nicely so:

@lines = File.find(params[:id]).lines

works nicely. The only problem is that if a line has a ‘\<’ in it,  
anything after the ‘\<’ is getting eaten (ie not showing up).

Any ideas?

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/2 "2007-10-03T18:00:29Z")

</div>

> anything after the ‘\<’ is getting eaten (ie not showing up).  
> Eaten up where? How are you verifying this? What happens if you run  
> the  
> above in script/console? Any chance it’s getting eaten because \< is  
> being  
> considered an html tag so swallowing the rest of the text perhaps  
> because  
> there isn’t a closing \> ? If so, look into escaping/encoding it before  
> you display it.

Maybe…

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 6:09pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/3 "2007-10-03T18:09:16Z")

</div>

Philip H. wrote:

> Eaten up where? How are you verifying this? What happens if you run the  
> above in script/console? Any chance it’s getting eaten because \< is being  
> considered an html tag so swallowing the rest of the text perhaps because  
> there isn’t a closing \> ? If so, look into escaping/encoding it before  
> you display it.
> 
> Maybe…  
> That’s exactly what is happening (I figured it out right after I  
> posted). I looked in the page source and all my text was there. the  
> browser sees the ‘\<’ and tried to resolve a tag out of it. when it  
> can’t all the text between it and the next valid closing tag is  
> eaten. I guess I’ll have to replace any ‘\<’ with ‘\<’ in my  
> controller before passing it to the view

Thanks

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/4 "2007-10-03T18:13:21Z")

</div>

On 3 Oct 2007, at 17:08, Reacher wrote:

> > before  
> > you display it.
> > 
> > Maybe…  
> > That’s exactly what is happening (I figured it out right after I  
> > posted). I looked in the page source and all my text was there. the  
> > browser sees the ‘\<’ and tried to resolve a tag out of it. when it  
> > can’t all the text between it and the next valid closing tag is  
> > eaten. I guess I’ll have to replace any ‘\<’ with ‘\<’ in my  
> > controller before passing it to the view

The h function will do that.

Fred

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/5 "2007-10-03T18:36:13Z")

</div>

> browser sees the ‘\<’ and tried to resolve a tag out of it. when it  
> can’t all the text between it and the next valid closing tag is  
> eaten. I guess I’ll have to replace any ‘\<’ with ‘\<’ in my  
> controller before passing it to the view

# Escape special characters in HTML, namely &"\<\>

CGI::escapeHTML('Usage: foo “bar” ')  
# =\> “Usage: foo “bar” \<baz\>”

---

<div class="post-metadata">

**Author:** ![reacher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@reacher](https://www.ruby-forum.com/u/reacher)\
**Post date:** [October 3, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/database-text-and/116232/6 "2007-10-03T19:49:35Z")

</div>

[http://www.gazeteport.com.tr/YAZARARANIYOR/NEWS/GP\_083040](http://www.gazeteport.com.tr/YAZARARANIYOR/NEWS/GP_083040)
