Bug with assert_select and javascript?

Hi, I am using Rails 2.2.2 and have some javascript in my html.erb file
in the body of the document, inside script tags. The script (which works
as intended) contains the line
for(var i=0; i<boxes.length; i++)
In my functional tests I use assert_select and it is generating a
warning “ignoring attempt to close boxes with script”. It appears to be
interpreting the text “<boxes” as the start of a tag. The only way I
have found to get round it is to add a javascript comment "// "
to the end of the line.
Is this a bug in assert_select or am I doing something foolish in my
ignorance?

Colin

On 13 Dec 2008, at 17:04, Colin L. wrote:

Hi, I am using Rails 2.2.2 and have some javascript in my html.erb
file
in the body of the document, inside script tags. The script (which
works
as intended) contains the line
is the javascript inside a <![CDATA[ section ?

fred

Frederick C. wrote:

On 13 Dec 2008, at 17:04, Colin L. wrote:

Hi, I am using Rails 2.2.2 and have some javascript in my html.erb
file
in the body of the document, inside script tags. The script (which
works
as intended) contains the line
is the javascript inside a <![CDATA[ section ?

fred

It wasn’t but it is now and is working, many thanks.

Colin

Colin L. wrote:

for(var i=0; i<boxes.length; i++)

Is this a bug in assert_select or am I doing something foolish in my
ignorance?

Ultimately the fault lies in zillions of web pages written with Notepad.

The Law (actually the Recommendations) say thou shalt escape < with
<. But
not all web pages treat & correctly, so browsers in turn cannot enforce
the
exact rules. And our tools follow suit!

You might be able to get by with < there.

Whatever the fix, you should move all but trivial JS up into
application.js or
some similar included file.

We dealt with && recently (in JS code we inexplicably had to add <% %>
tags to)
by writing function aaaand(q,k){ return q && k; }. We put aaaand up in
application.js, but note this hack turns off boolean short-circuiting!


Phlip