mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Stricter handling of warning headers
This commit is contained in:
parent
7f98c48828
commit
f14055cb8d
3 changed files with 38 additions and 2 deletions
|
@ -179,9 +179,9 @@ export function initializeInput($el, $actionsEl, $copyAsCurlEl, output) {
|
|||
var warnings = xhr.getResponseHeader("warning");
|
||||
if (warnings) {
|
||||
// pattern for valid warning header
|
||||
var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/
|
||||
var re = /\d{3} [0-9a-zA-Z!#$%&'*+-.^_`|~]+ \"((?:\t| |!|[\x23-\x5b]|[\x5d-\x7e]|[\x80-\xff]|\\\\|\\")*)\"(?: \"[^"]*\")/
|
||||
// split on any comma that is followed by an even number of quotes
|
||||
warnings = _.map(warnings.split(/, (?=(?:[^"]*\"[^"]*\")*[^"]*$)/), function (warning) {
|
||||
warnings = _.map(utils.splitOnUnquotedCommaSpace(warnings), function (warning) {
|
||||
var match = re.exec(warning)
|
||||
// extract the actual warning if there was a match
|
||||
return "#! Deprecation: " + (match !== null ? match[1] : warning)
|
||||
|
|
|
@ -56,4 +56,29 @@ utils.expandLiteralStrings = function (data) {
|
|||
});
|
||||
}
|
||||
|
||||
utils.splitOnUnquotedCommaSpace = function (s) {
|
||||
var quoted = false;
|
||||
var arr = [];
|
||||
var buffer = '';
|
||||
var i = 0
|
||||
while (i < s.length) {
|
||||
var token = s.charAt(i++)
|
||||
if (token == '\\' && i < s.length) {
|
||||
token += s.charAt(i++)
|
||||
} else if (token == ',' && i < s.length && s.charAt(i) == ' ') {
|
||||
token += s.charAt(i++);
|
||||
}
|
||||
if (token == '"') {
|
||||
quoted = !quoted
|
||||
} else if (!quoted && token == ', ') {
|
||||
arr.push(buffer);
|
||||
buffer = '';
|
||||
continue
|
||||
}
|
||||
buffer += token;
|
||||
}
|
||||
arr.push(buffer)
|
||||
return arr;
|
||||
}
|
||||
|
||||
module.exports = utils;
|
||||
|
|
|
@ -33,4 +33,15 @@ _.each(expandingTests.split(/^=+$/m), function (fixture) {
|
|||
test("Literal expand - " + name, function () {
|
||||
deepEqual(utils.expandLiteralStrings(collapsed), expanded);
|
||||
});
|
||||
|
||||
test("split on unquoted comma followed by space", function () {
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('a, b'), ['a', 'b']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('a,b, c'), ['a,b', 'c']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('"a, b"'), ['"a, b"']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('"a, b", c'), ['"a, b"', 'c']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('"a, b\\", c"'), ['"a, b\\", c"']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace(', a, b'), ['', 'a', 'b']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('a, b, '), ['a', 'b', '']);
|
||||
deepEqual(utils.splitOnUnquotedCommaSpace('\\"a, b", "c, d\\", e", f"'), ['\\"a', 'b", "c', 'd\\"', 'e", f"']);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue