Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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