mirror of https://github.com/zulip/zulip.git
Trim search operand from the end until URI decoding succeeds
Fixes #1137. (imported from commit a23219d2cefdc2b739a165c88780fba409d4d878)
This commit is contained in:
parent
a8816f81c0
commit
b7bb598e02
|
@ -51,7 +51,7 @@ function encodeOperand(operand) {
|
|||
}
|
||||
|
||||
function decodeOperand(encoded) {
|
||||
return decodeURIComponent(encoded.replace(/\+/g, ' '));
|
||||
return util.robust_uri_decode(encoded.replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
/* Convert a list of operators to a string.
|
||||
|
|
|
@ -202,5 +202,23 @@ exports.same_sender = function util_same_sender(a, b) {
|
|||
(a.sender_email === b.sender_email));
|
||||
};
|
||||
|
||||
// Avoid URI decode errors by removing characters from the end
|
||||
// one by one until the decode succeeds. This makes sense if
|
||||
// we are decoding input that the user is in the middle of
|
||||
// typing.
|
||||
exports.robust_uri_decode = function (str) {
|
||||
var end = str.length;
|
||||
while (end > 0) {
|
||||
try {
|
||||
return decodeURIComponent(str.substring(0, end));
|
||||
} catch (e) {
|
||||
if (!(e instanceof URIError))
|
||||
throw e;
|
||||
end--;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
return exports;
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue