Forum: Ruby on Rails Bug with assert_select and javascript?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6979c3a1112df9ce66e2171258d948f5?d=identicon&s=25 Colin Law (colinl)
on 2008-12-13 18:04
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 "// </boxes>"
to the end of the line.
Is this a bug in assert_select or am I doing something foolish in my
ignorance?

Colin
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-13 18:30
(Received via mailing list)
On 13 Dec 2008, at 17:04, Colin Law 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
6979c3a1112df9ce66e2171258d948f5?d=identicon&s=25 Colin Law (colinl)
on 2008-12-13 18:43
Frederick Cheung wrote:
> On 13 Dec 2008, at 17:04, Colin Law 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
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2008-12-14 03:08
(Received via mailing list)
Colin Law 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
&lt;. 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 &lt; 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
This topic is locked and can not be replied to.