Permalink
Browse files

hemlock.utils.JavaScript: Escaped double-quotes in alert() and log()

  • Loading branch information...
1 parent 6d89546 commit 467b34689aef6a4e9c6bee27e65bdd24d5c4b828 @rondevera rondevera committed Apr 20, 2010
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/com/mintdigital/hemlock/utils/JavaScript.as
View
21 src/com/mintdigital/hemlock/utils/JavaScript.as
@@ -22,9 +22,10 @@ package com.mintdigital.hemlock.utils{
return;
}
+ var escapedArg:String;
args.forEach(function(arg:*, index:int, array:Array):void{
- run('function(){ alert("' + arg + '"); }');
- // TODO: Add escaping of double quotes
+ escapedArg = arg.replace(new RegExp('"', 'gm'), '\\"');
+ run('function(){ alert("' + escapedArg + '"); }');
});
}
@@ -33,10 +34,20 @@ package com.mintdigital.hemlock.utils{
Logger.error('JavaScript::log() : ExternalInterface not available.');
return;
}
-
+
+ var escapedArg:String;
args.forEach(function(arg:*, index:int, array:Array):void{
- run('function(){ if(console && console.log){ console.log("' + arg + '"); }else{ alert("' + arg + '"); } }');
- // TODO: Add escaping of double quotes
+ escapedArg = arg.replace(new RegExp('"', 'gm'), '\\"');
+ run(
+ (<![CDATA[ function(){
+ if(window.console && window.console.log){
+ window.console.log("{{arg}}");
+ }else{
+ alert("{{arg}}");
+ }
+ } ]]>).toString().
+ replace(new RegExp('{{arg}}', 'gm'), escapedArg)
+ );
});
}

0 comments on commit 467b346

Please sign in to comment.