Skip to content

Commit

Permalink
[Console] Update copy when showing warnings in response headers (#94270)
Browse files Browse the repository at this point in the history
* remove "deprecated: " from console warning

* refactor "deprecation" to "warning"

* complete name refactor in test files
  • Loading branch information
jloleysens authored Mar 11, 2021
1 parent 77fe83b commit 1618e54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { extractDeprecationMessages } from '../../../lib/utils';
import { extractWarningMessages } from '../../../lib/utils';
import { XJson } from '../../../../../es_ui_shared/public';
const { collapseLiteralStrings } = XJson;
// @ts-ignore
Expand Down Expand Up @@ -88,8 +88,8 @@ export function sendRequestToES(args: EsRequestArgs): Promise<ESRequestResult[]>

const warnings = xhr.getResponseHeader('warning');
if (warnings) {
const deprecationMessages = extractDeprecationMessages(warnings);
value = deprecationMessages.join('\n') + '\n' + value;
const warningMessages = extractWarningMessages(warnings);
value = warningMessages.join('\n') + '\n' + value;
}

if (isMultiRequest) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/console/public/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export function formatRequestBodyDoc(data: string[], indent: boolean) {
};
}

export function extractDeprecationMessages(warnings: string) {
export function extractWarningMessages(warnings: string) {
// pattern for valid warning header
const 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
return _.map(splitOnUnquotedCommaSpace(warnings), (warning) => {
const match = re.exec(warning);
// extract the actual warning if there was a match
return '#! Deprecation: ' + (match !== null ? unescape(match[1]) : warning);
return '#! ' + (match !== null ? unescape(match[1]) : warning);
});
}

Expand Down
32 changes: 16 additions & 16 deletions src/plugins/console/public/lib/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,51 @@ import * as utils from '.';
describe('Utils class', () => {
test('extract deprecation messages', function () {
expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning" "Mon, 27 Feb 2017 14:52:14 GMT"'
)
).toEqual(['#! Deprecation: this is a warning']);
).toEqual(['#! this is a warning']);
expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning"'
)
).toEqual(['#! Deprecation: this is a warning']);
).toEqual(['#! this is a warning']);

expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning" "Mon, 27 Feb 2017 14:52:14 GMT", 299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a second warning" "Mon, 27 Feb 2017 14:52:14 GMT"'
)
).toEqual(['#! Deprecation: this is a warning', '#! Deprecation: this is a second warning']);
).toEqual(['#! this is a warning', '#! this is a second warning']);
expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning", 299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a second warning"'
)
).toEqual(['#! Deprecation: this is a warning', '#! Deprecation: this is a second warning']);
).toEqual(['#! this is a warning', '#! this is a second warning']);

expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning, and it includes a comma" "Mon, 27 Feb 2017 14:52:14 GMT"'
)
).toEqual(['#! Deprecation: this is a warning, and it includes a comma']);
).toEqual(['#! this is a warning, and it includes a comma']);
expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning, and it includes a comma"'
)
).toEqual(['#! Deprecation: this is a warning, and it includes a comma']);
).toEqual(['#! this is a warning, and it includes a comma']);

expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning, and it includes an escaped backslash \\\\ and a pair of \\"escaped quotes\\"" "Mon, 27 Feb 2017 14:52:14 GMT"'
)
).toEqual([
'#! Deprecation: this is a warning, and it includes an escaped backslash \\ and a pair of "escaped quotes"',
'#! this is a warning, and it includes an escaped backslash \\ and a pair of "escaped quotes"',
]);
expect(
utils.extractDeprecationMessages(
utils.extractWarningMessages(
'299 Elasticsearch-6.0.0-alpha1-SNAPSHOT-abcdef1 "this is a warning, and it includes an escaped backslash \\\\ and a pair of \\"escaped quotes\\""'
)
).toEqual([
'#! Deprecation: this is a warning, and it includes an escaped backslash \\ and a pair of "escaped quotes"',
'#! this is a warning, and it includes an escaped backslash \\ and a pair of "escaped quotes"',
]);
});

Expand Down

0 comments on commit 1618e54

Please sign in to comment.