Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8112 (assigned defect)

Opened 2 years ago

Last modified 1 year ago

[PATCH][fixed \w Prototype.exec()] IE w/ Ajax.Request.evalResponse() and script comments

Reported by: pprasse Assigned to: jdalton (accepted)
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords:
Cc: chewi

Description

When using Ajax.Updater with the option evalScripts:true like:

  new Ajax.Updater( table_id+'tbody', '/someurl', {
    parameters : { 'table_id':table_id },
    evalScripts : true
  });

and response of /someurl contains the following script:

<script language="JavaScript" type="text/javascript">
<!--
alert( 'Hello' );
// -->
</script>

IE7 throws an error "Syntax error" in line 212 of prototype.js version 1.5.0 in function evalScripts.

If you try a non-commented script like:

<script language="JavaScript" type="text/javascript">
alert( 'Hello' );
</script>

it works. Firefox works whether the script is commented or not. I had no chance to test it in IE6.

Attachments

ajax_prototype_exec_used.diff (422 bytes) - added by jdalton on 03/31/08 05:42:26.
string_prototype_exec_used.diff (1 bytes) - added by jdalton on 04/17/08 07:03:01.
Deleted

Change History

01/14/08 19:06:45 changed by shougun

This issue persists in Prototype 1.6.0

It is a problem with the eval function in IE which doesn't consider '<!--' to be valid syntax.

The problem can be worked around by looking for and removing the HTML comment start tag from any script prior to it being evaluated:

String.prototype.evalScripts = function() {
  return this.extractScripts().map(function(script) { 
      script = script.replace(/^[\s]*<!--/,''); // new line
      return eval(script); 
    });
};

01/18/08 15:02:58 changed by chewi

  • cc set to chewi.

This also affects IE6.

01/18/08 15:08:58 changed by chewi

I should add that using //<![CDATA[ and //]]> works okay. I believe this is recommended over the old HTML comment tag for XHTML pages.

03/24/08 22:29:10 changed by jdalton

  • owner changed from sam to jdalton.
  • status changed from new to assigned.

03/24/08 22:30:25 changed by jdalton

  • summary changed from evalScripts problem in IE7 w/ Ajax.Updater and evalScripts:true and commented scripts to [fixed \w Prototype.exec()] evalScripts problem in IE w/ Ajax.Updater and evalScripts:true and commented scripts.

This issue is fixed when using Prototype.exec() the proposed solution to global eval. http://pastie.caboo.se/169871

03/25/08 18:24:33 changed by jdalton

ticket for Prototype.exec() addition: http://dev.rubyonrails.org/ticket/11423

03/31/08 05:42:26 changed by jdalton

  • attachment ajax_prototype_exec_used.diff added.

03/31/08 05:43:51 changed by jdalton

03/31/08 05:45:59 changed by jdalton

  • summary changed from [fixed \w Prototype.exec()] evalScripts problem in IE w/ Ajax.Updater and evalScripts:true and commented scripts to [PATCH][fixed \w Prototype.exec()] IE w/ Ajax.Request.evalResponse() and script comments.

04/17/08 07:03:01 changed by jdalton

  • attachment string_prototype_exec_used.diff added.

Deleted