BUGFIX Support for commas in URLs processed by Requirements and jQuery.ondemand (which uses commas to serialise its dependency data into HTTP headers)

This commit is contained in:
Ingo Schommer 2012-01-06 14:09:43 +01:00
parent 5ec6aa532c
commit 6dd3dc9f59
2 changed files with 17 additions and 7 deletions

View File

@ -15,6 +15,10 @@
*/
(function($){
var decodePath = function(str) {
return str.replace(/%2C/g,',').replace(/\&/g, '&');
};
$.extend({
// loaded files list - to protect against loading existed file again (by PGA)
@ -50,7 +54,7 @@
});
}
return (this._ondemand_loaded_list[scriptUrl] != undefined);
return (this._ondemand_loaded_list[decodePath(scriptUrl)] != undefined);
},
requireCss : function(styleUrl, media){
@ -89,10 +93,10 @@
for(var i=0;i<cssIncludes.length;i++) {
// Syntax: "URL:##:media"
if(cssIncludes[i].match(/^(.*):##:(.*)$/)) {
$.requireCss(RegExp.$1, RegExp.$2);
$.requireCss(decodePath(RegExp.$1), RegExp.$2);
// Syntax: "URL"
} else {
$.requireCss(cssIncludes[i]);
$.requireCss(decodePath(cssIncludes[i]));
}
}
}
@ -102,8 +106,9 @@
if(xhr.getResponseHeader && xhr.getResponseHeader('X-Include-JS')) {
var jsIncludes = xhr.getResponseHeader('X-Include-JS').split(',');
for(var i=0;i<jsIncludes.length;i++) {
if(!$.isItemLoaded(jsIncludes[i])) {
newJsIncludes.push(jsIncludes[i]);
var jsIncludePath = decodePath(jsIncludes[i]);
if(!$.isItemLoaded(jsIncludePath)) {
newJsIncludes.push(jsIncludePath);
}
}
}

View File

@ -726,14 +726,19 @@ class Requirements_Backend {
foreach(array_diff_key($this->javascript, $this->blocked) as $file => $dummy) {
$path = $this->path_for_file($file);
if($path) $jsRequirements[] = $path;
if($path) {
$jsRequirements[] = str_replace(',', '%2C', $path);
}
}
$response->addHeader('X-Include-JS', implode(',', $jsRequirements));
foreach(array_diff_key($this->css,$this->blocked) as $file => $params) {
$path = $this->path_for_file($file);
if($path) $cssRequirements[] = isset($params['media']) ? "$path:##:$params[media]" : $path;
if($path) {
$path = str_replace(',', '%2C', $path);
$cssRequirements[] = isset($params['media']) ? "$path:##:$params[media]" : $path;
}
}
$response->addHeader('X-Include-CSS', implode(',', $cssRequirements));