Correct display of warning header#10470
Conversation
Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header.
|
@epixa I discussed this with @clintongormley. As it currently stands, this feature is buggy in case Elasticsearch sends back a warning header that contains a comma (for example, |
| warnings = _.map(warnings.split(", "), function (warning) { | ||
| return "#! Deprecation: " + warning; | ||
| // pattern for valid warning header | ||
| var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/ |
There was a problem hiding this comment.
should this support escaped quotes in the message?
There was a problem hiding this comment.
That's a good question but I do not think it's necessary. The warning headers produced by Elasticsearch will not contained escaped quotes.
There was a problem hiding this comment.
A regex to handle escaped quotes and escaped backslashes would look like this:
var re = /\d{3} \S+ \"((?:\\[\\"]|[^"])*)\"( \"(?:\\[\\"]|[^"])*\")/
There was a problem hiding this comment.
Learning from the regex master: do we need the extra \\ in [\\"] ?
There was a problem hiding this comment.
Ah you've just pointed out a flaw in my regex. Not such a master now! In fact it should be:
"((?:[^"\\]|\\.)*)"
Which means:
- match
" - capture:
- zero or more times: match any character except
\or"or match\followed by any character
- zero or more times: match any character except
- match
"
So it'd match this correctly:
"Here is an embedded \\ and a \" quote and \n"
That handles any backslashed character, not just quotes
There was a problem hiding this comment.
Bah - ignore me. This would work (which is what I think you were suggesting):
"((?:\\"|[^"])*)"
Which says:
- match
* - capture:
- zero or more times: match
\"or any character except"
- zero or more times: match
- match
"
There was a problem hiding this comment.
After additional discussion with @clintongormley and @bleskes, it has been agreed that we should allow escaped quotes in warning messages, so I will work on a change on both sides to support them. Thanks for raising the question @jbudz. 😄
| var re = /\d{3} [^ ]+ \"([^"]*)\"( \"[^"]*\")/ | ||
| // split on any comma that is followed by an even number of quotes | ||
| warnings = _.map(warnings.split(/, (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/), function (warning) { | ||
| var match = re.exec(warning) |
There was a problem hiding this comment.
if there's no match, accessing match[1] will cause a full screen fatal error. thoughts on a match !== null check?
There was a problem hiding this comment.
This is a good point. The warning headers produced by Elasticsearch should always match this pattern but I think your suggestion to err on the side of safety is a good one.
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.
|
I kicked off a new build on this because the old one aborted on jenkins: https://kibana-ci.elastic.co/job/elastic+kibana+pull-request+multijob-selenium/2722/console |
tylersmalley
left a comment
There was a problem hiding this comment.
LGTM - tested against #10470
bleskes
left a comment
There was a problem hiding this comment.
Thanks @jasontedor for picking this side of the equation as well. Can we add a unit test for the regexes (I can help with where to put them and how to run). Also I think we should deal with escaping properly so we never have to worry about this again.
| 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) |
There was a problem hiding this comment.
we should unescape a match... Also, I wonder if it's got have all of this as a util method (i.e., extractDeprecationMessages ) and test it.
| }); | ||
| } | ||
|
|
||
| utils.splitOnUnquotedCommaSpace = function (s) { |
|
Is this backwards compatible with the old warning headers? In other words, is it safe to merge even if the Elasticsearch PR isn't in? |
|
The corresponding Elasticsearch PR went in, so my question is no longer valid. @jbudz can you merge/backport this to 5.3? |
Backports PR #10470 **Commit 1:** Correct display of warning header Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header. * Original sha: 02896ea * Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z **Commit 2:** 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. * Original sha: 7f98c48 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z **Commit 3:** Stricter handling of warning headers * Original sha: f14055c * Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z **Commit 4:** Add tests for deprecation messages * Original sha: 8a9f432 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
Backports PR #10470 **Commit 1:** Correct display of warning header Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header. * Original sha: 02896ea * Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z **Commit 2:** 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. * Original sha: 7f98c48 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z **Commit 3:** Stricter handling of warning headers * Original sha: f14055c * Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z **Commit 4:** Add tests for deprecation messages * Original sha: 8a9f432 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
Backports PR #10470 **Commit 1:** Correct display of warning header Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header. * Original sha: 02896ea * Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z **Commit 2:** 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. * Original sha: 7f98c48 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z **Commit 3:** Stricter handling of warning headers * Original sha: f14055c * Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z **Commit 4:** Add tests for deprecation messages * Original sha: 8a9f432 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
Backports PR #10470 **Commit 1:** Correct display of warning header Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header. * Original sha: 02896ea * Authored by Jason Tedor <jason@tedor.me> on 2017-02-20T20:44:14Z **Commit 2:** 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. * Original sha: 7f98c48 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-22T20:23:35Z **Commit 3:** Stricter handling of warning headers * Original sha: f14055c * Authored by Jason Tedor <jason@tedor.me> on 2017-02-24T19:08:28Z **Commit 4:** Add tests for deprecation messages * Original sha: 8a9f432 * Authored by Jason Tedor <jason@tedor.me> on 2017-02-27T15:42:56Z
|
Thanks all for the reviews. |
Elasticsearch produces warning headers for the use of deprecated features. These warning headers can contain commas which breaks the splitting of multiple values on commas. Upstream Elasticsearch has changed the warning headers to be specification compliant so that these headers can be safely split (the warning text and warning date must be quoted, so splits should only occur on commas that are not contained in quotes). Additionally, the upstream change includes additional details that are not needed for display in Console (a warning code, the Elasticsearch version that produced the warning, and the warning date). This commit corrects the splitting logic in Console to only split on commas not contained in quotes, and to extract the warning text from each warning header.
Relates elastic/elasticsearch#23275