Changeset 358


Ignore:
Timestamp:
01/15/2010 02:57:13 AM (2 years ago)
Author:
ofer
Message:

Use internal JSON object or new Function instead of eval

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposh.js

    r353 r358  
    413413            }); 
    414414 
     415            var translationstats, possibly_translateable, now; 
    415416            // now lets check if auto translate is needed 
    416             var translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"), possibly_translateable, now; 
     417            translationstats = jQuery("meta[name=translation-stats]").attr("content"); 
     418            // Logic borrowed from jquery and http://json.org/json2.js - Didn't see the reason for that, if someone can modify the html, he can probably do any script he wants too... 
     419            /*if (/^[\],:{}\s]*$/.test(translationstats.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") 
     420                .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") 
     421                .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {*/ 
     422 
     423            // Try to use the native JSON parser first 
     424            if (window.JSON && window.JSON.parse) { 
     425                translationstats = window.JSON.parse(translationstats); 
     426 
     427            } else { 
     428                translationstats = (new Function("return " + translationstats))(); 
     429            } 
     430 
     431            /*} else { 
     432                                        throw "Invalid JSON: " + data; 
     433                                }*/ 
     434 
     435            //            var translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"), possibly_translateable, now; 
    417436            if (translationstats !== undefined) { 
    418437                possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases - (translationstats.meta_phrases - translationstats.meta_translated_phrases)); 
Note: See TracChangeset for help on using the changeset viewer.