[Console] Update copy when showing warnings in response headers (#94270) (#94402)

* remove "deprecated: " from console warning

* refactor "deprecation" to "warning"

* complete name refactor in test files
This commit is contained in:
Jean-Louis Leysens 2021-03-11 12:39:17 +01:00 committed by GitHub
parent 088525c003
commit be49344385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 21 deletions

View file

@ -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
@ -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) {

View file

@ -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);
});
}

View file

@ -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"',
]);
});