Escape backslashes in regexps in Loki label browser (#45809, #47039). (#47412)

* Escape backslashes in regexps in Loki label browser (#45809, #47039).

* Escape values in Loki Query Builder.

* Escape more values in Loki Query Builder.
This commit is contained in:
Alexander Kubyshkin
2022-05-04 13:49:04 +03:00
committed by GitHub
parent b0f41b9772
commit f00ffb190c
7 changed files with 89 additions and 18 deletions

View File

@ -17,7 +17,7 @@ import { LocalStorageValueProvider } from 'app/core/components/LocalStorageValue
import { LokiDatasource } from '../datasource';
import LokiLanguageProvider from '../language_provider';
import { shouldRefreshLabels } from '../language_utils';
import { escapeLabelValueInSelector, shouldRefreshLabels } from '../language_utils';
import { LokiQuery, LokiOptions } from '../types';
import { LokiLabelBrowser } from './LokiLabelBrowser';
@ -47,17 +47,26 @@ function willApplySuggestion(suggestion: string, { typeaheadContext, typeaheadTe
case 'context-label-values': {
// Always add quotes and remove existing ones instead
let suggestionModified = '';
if (!typeaheadText.match(/^(!?=~?"|")/)) {
suggestion = `"${suggestion}`;
suggestionModified = '"';
}
suggestionModified += escapeLabelValueInSelector(suggestion, typeaheadText);
if (DOMUtil.getNextCharacter() !== '"') {
suggestion = `${suggestion}"`;
suggestionModified += '"';
}
suggestion = suggestionModified;
break;
}
default:
}
return suggestion;
}