Changeset 8812

Show
Ignore:
Timestamp:
05/29/07 15:51:42 (18 months ago)
Author:
alex
Message:

adding "json-comment-optional" handleAs type. Refs #2520

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/_base/xhr.js

    r8547 r8812  
    172172                console.debug("please consider using a mimetype of text/json-comment-filtered to avoid potential security issues with JSON endpoints"); 
    173173                return dojo.fromJson(xhr.responseText); 
     174        }, 
     175        "json-comment-optional": function(xhr){  
     176                // NOTE: we provide the json-comment-filtered option as one solution to 
     177                // the "JavaScript Hijacking" issue noted by Fortify and others. It is 
     178                // not appropriate for all circumstances. 
     179                var value = xhr.responseText; 
     180                var cStartIdx = value.indexOf("\/*"); 
     181                var cEndIdx = value.lastIndexOf("*\/"); 
     182                if((cStartIdx == -1)||(cEndIdx == -1)){ 
     183                        return dojo.fromJson(xhr.responseText); 
     184                } 
     185                return dojo.fromJson(value.substring(cStartIdx+2, cEndIdx)); 
    174186        }, 
    175187        "json-comment-filtered": function(xhr){