This project is archived and is in readonly mode.

#4849 ✓invalid
Ernesto

set_focus_to_id inside page.replace_html or insert_html error

Reported by Ernesto | June 13th, 2010 @ 05:03 AM

Hi,

I don't know much about ruby, nor rails, nor reporting bugs, nor anything.
But I think I've found a bug in rails 2.3.8.

I have made a test case with the following files:

test.erb:

<!-- begin test.erb -->
<form>
<%= text_field(:test, :dna, {:value => @test.dna, :size => "8", :maxlength
=> "9"})%>
<%= submit_tag "Test" %>
</form>


<div id="new"> </div>


<%= update_page_tag { |page| page[:new].replace_html(render(:partial => 'test_partial' ) ) } %>


<%= set_focus_to_id 'test_dna' %>


<!-- end test.erb -->

test_partial.erb

<!-- begin test_partial.erb -->


<h1>There is a problem somewhere around here!!</h1> <%= set_focus_to_id "it_doesnt_matter" %>


<!-- end _test_partial.erb -->

This is generating erroneous javascript in the output file (HTML) like:

<!-- begin bad script -->
<script type="text/javascript">
//<![CDATA[
try {
$("new").update("<h1>There is a problem somewhere around here!!</h1>\n

<script type=\"text/javascript\">
\n//<![CDATA[\n$('it_doesnt_matter').focus()\n//]]>\n
</script>

 \n");
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('$(\"new\").update(\"<h1>There is a problem somewhere around
here!!</h1>\\n

<script type=\\\"text/javascript\\\">\\n//
<![CDATA[\\n$(\'it_doesnt_matter\').focus()\\n//]]>\\n
</script>

 \\n\");'); throw e }
//]]>

</script>

<script type="text/javascript">
//<![CDATA[
$('test_dna').focus()
//]]>
</script>
<!-- end bad script -->

The same test code in rails 1.2.6 renders as it should be, escaping some characters:

<!-- begin good script -->
<script type="text/javascript">
//<![CDATA[
try {
$("new").update("\074h1\076There is a problem somewhere around
here!!\074/h1\076\n\074script
type=\"text/javascript\"\076\n//\074![CDATA[\n$('it_doesnt_matter').focus()\n//]]\076\n\074/script\076
 \n");
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('$(\"new\").update(\"\\074h1\\076There is a problem somewhere around
here!!\\074/h1\\076\\n\\074script
type=\\\"text/javascript\\\"\\076\\n//\\074![CDATA[\\n$(\'it_doesnt_matter\').focus()\\n//]]\\076\\n\\074/script\\076
 \\n\");'); throw e }
//]]>
</script>

<script type="text/javascript">
//<![CDATA[
$('test_dna').focus()
//]]>
</script>

<!-- end good script -->

I could try to track the problem further, but I have no idea where to
look.

Any help will be appreciated.

Regards,

Ernesto

Comments and changes to this ticket

  • Ernesto

    Ernesto June 13th, 2010 @ 08:36 PM

    Hi,

    there is no bug :$

    The behavior I want can be set in config/initializers/new_rails_defaults.rb, with the option

    ActiveSupport.escape_html_entities_in_json = true

    I'm sorry. I'd like to close the ticket.

    Regards,

    Ernesto.

  • Rohit Arondekar

    Rohit Arondekar June 15th, 2010 @ 09:44 AM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages