Database text and '<'

I just typed a long post with my model, controller and view file
snippets, and lost it :frowning: 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?

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…

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

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

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>”

http://www.gazeteport.com.tr/YAZARARANIYOR/NEWS/GP_083040

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