Changeset 7811

Show
Ignore:
Timestamp:
03/27/07 16:17:07 (2 years ago)
Author:
alex
Message:

adding a text/json-comment-filtered type to the IO system. Refs #2656

Location:
trunk
Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/io/BrowserIO.js

    r7146 r7811  
    281281                                        ret = null; 
    282282                                } 
    283                         }else if(kwArgs.mimetype == "text/json" || kwArgs.mimetype == "application/json"){ 
     283                        }else if(kwArgs.mimetype.substr(0, 9) == "text/json" || kwArgs.mimetype.substr(0, 16) == "application/json"){ 
    284284                                try{ 
    285                                         ret = dj_eval("("+http.responseText+")"); 
     285                                        ret = dj_eval("("+kwArgs.jsonFilter(http.responseText)+")"); 
    286286                                }catch(e){ 
    287287                                        dojo.debug(e); 
     
    397397                // multi-part mime encoded and avoid using this transport for those 
    398398                // requests. 
     399                var mlc = kwArgs["mimetype"].toLowerCase()||""; 
    399400                return hasXmlHttp 
    400                         && dojo.lang.inArray(["text/plain", "text/html", "application/xml", "text/xml", "text/javascript", "text/json", "application/json"], (kwArgs["mimetype"].toLowerCase()||"")) 
     401                        && ( 
     402                                ( 
     403                                        dojo.lang.inArray([ 
     404                                                "text/plain", "text/html", "application/xml",  
     405                                                "text/xml", "text/javascript" 
     406                                                ], mlc 
     407                                        ) 
     408                                ) || ( 
     409                                        mlc.substr(0, 9) == "text/json" || mlc.substr(0, 16) == "application/json" 
     410                                ) 
     411                        ) 
    401412                        && !( kwArgs["formNode"] && dojo.io.formHasFile(kwArgs["formNode"]) ); //boolean 
    402413        } 
  • trunk/src/io/common.js

    r6675 r7811  
    113113        /** Prevent the browser from caching this by adding a query string argument to the URL */ 
    114114        preventCache: false, 
     115 
     116        jsonFilter: function(value){ 
     117                if(     (this.mimetype == "text/json-comment-filtered")|| 
     118                        (this.mimetype == "application/json-comment-filtered") 
     119                ){ 
     120                        var cStartIdx = value.indexOf("\/*"); 
     121                        var cEndIdx = value.lastIndexOf("*\/"); 
     122                        if((cStartIdx == -1)||(cEndIdx == -1)){ 
     123                                dojo.debug("your JSON wasn't comment filtered!"); // FIXME: throw exception instead? 
     124                                return ""; 
     125                        } 
     126                        return value.substring(cStartIdx+2, cEndIdx); 
     127                } 
     128                dojo.debug("please consider using a mimetype of text/json-comment-filtered to avoid potential security issues with JSON endpoints"); 
     129                return value; 
     130        }, 
    115131         
    116132        // events stuff