Safer regex handling

If the warning header from Elasticsearch comes back in the wrong format,
this could lead to the regex not matching which would lead to a
blow-up. While Elasticsearch should not do this, let us be defensive
here.
This commit is contained in:
Jason Tedor 2017-02-22 15:23:35 -05:00
parent 02896eaed7
commit 7f98c48828

View file

@ -181,10 +181,10 @@ export function initializeInput($el, $actionsEl, $copyAsCurlEl, output) {
// pattern for valid warning header
var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/
// split on any comma that is followed by an even number of quotes
warnings = _.map(warnings.split(/, (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/), function (warning) {
warnings = _.map(warnings.split(/, (?=(?:[^"]*\"[^"]*\")*[^"]*$)/), function (warning) {
var match = re.exec(warning)
// extract the actual warning
return "#! Deprecation: " + match[1]
// extract the actual warning if there was a match
return "#! Deprecation: " + (match !== null ? match[1] : warning)
});
value = warnings.join("\n") + "\n" + value;
}