Ox.decodeURI/Ox.decodeURIComponent: replace all '%' with '%25' that are not part of valid UTF8 sequence (fixes #1841)
This commit is contained in:
parent
4c390cc236
commit
7693079b8c
1 changed files with 39 additions and 16 deletions
|
@ -24,23 +24,46 @@ Ox.clean = function(string) {
|
||||||
})).join('\n');
|
})).join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
(function() {
|
||||||
Ox.decodeURIComponent <f> Decodes URI
|
|
||||||
|
function replace(string) {
|
||||||
|
return string.replace(/%(?![0-9A-Fa-f]{2})/g, '%25')
|
||||||
|
.replace(/(%[0-9A-Fa-f]{2})+/g, function(match) {
|
||||||
|
var hex = match.split('%').slice(1), ret;
|
||||||
|
Ox.forEach(Ox.range(1, hex.length + 1), function(length) {
|
||||||
|
var string = Ox.range(length).map(function(i) {
|
||||||
|
return Ox.char(parseInt(hex[i], 16));
|
||||||
|
}).join('');
|
||||||
|
try {
|
||||||
|
Ox.decodeUTF8(string);
|
||||||
|
ret = match.slice(0, length * 3)
|
||||||
|
+ match.slice(length * 3).replace(/%/g, '%25');
|
||||||
|
return false;
|
||||||
|
} catch(e) {}
|
||||||
|
});
|
||||||
|
return ret || '%25' + hex[0] + replace(match.slice(3));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*@
|
||||||
|
Ox.decodeURI <f> Decodes URI
|
||||||
Unlike window.decodeURI, this doesn't throw on trailing '%'.
|
Unlike window.decodeURI, this doesn't throw on trailing '%'.
|
||||||
(string) -> <s> Decoded string
|
(string) -> <s> Decoded string
|
||||||
@*/
|
@*/
|
||||||
Ox.decodeURI = function(string) {
|
Ox.decodeURI = function(string) {
|
||||||
return decodeURIComponent(string.replace(/%(?![0-9A-F]{2})/g, '%25'));
|
return decodeURI(replace(string));
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.decodeURIComponent <f> Decodes URI component
|
Ox.decodeURIComponent <f> Decodes URI component
|
||||||
Unlike window.decodeURIComponent, this doesn't throw on trailing '%'.
|
Unlike window.decodeURIComponent, this doesn't throw on trailing '%'.
|
||||||
(string) -> <s> Decoded string
|
(string) -> <s> Decoded string
|
||||||
@*/
|
@*/
|
||||||
Ox.decodeURIComponent = function(string) {
|
Ox.decodeURIComponent = function(string) {
|
||||||
return decodeURIComponent(string.replace(/%(?![0-9A-F]{2})/g, '%25'));
|
return decodeURIComponent(replace(string));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.endsWith <f> Tests if a string ends with a given substring
|
Ox.endsWith <f> Tests if a string ends with a given substring
|
||||||
|
|
Loading…
Reference in a new issue