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?

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).

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 Hallstrom 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 '&lt;' in my
controller before passing it to the view

Thanks

Philip Hallstrom 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 '&lt;' in my
controller before passing it to the view

Thanks

The h function will do that.

Fred

Philip Hallstrom 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 '&lt;' in my
controller before passing it to the view

# Escape special characters in HTML, namely &\"<>
CGI::escapeHTML('Usage: foo "bar" <baz>')
      # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"