mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* WIP: intial commit * Switch: Adds tooltip * Refactor: Adds props to LogsPanelEditor * Refactor: Moves LogRowContextProvider to grafana/ui * Refactor: Moves LogRowContext and Alert to grafana/ui * Refactor: Moves LogLabelStats to grafana/ui * Refactor: Moves LogLabels and LogLabel to grafana/ui * Refactor: Moves LogMessageAnsi and ansicolor to grafana/ui * Refactor: Moves calculateFieldStats, LogsParsers and getParser to grafana/data * Refactor: Moves findHighlightChunksInText to grafana/data * Refactor: Moves LogRow to grafana/ui * Refactor: Moving ExploreGraphPanel to grafana/ui * Refactor: Copies Logs to grafana/ui * Refactor: Moves ToggleButtonGroup to grafana/ui * Refactor: Adds Logs to LogsPanel * Refactor: Moves styles to emotion * Feature: Adds LogsRows * Refactor: Introduces render limit * Styles: Moves styles to emotion * Styles: Moves styles to emotion * Styles: Moves styles to emotion * Styles: Moves styles to emotion * Refactor: Adds sorting to LogsPanelEditor * Tests: Adds tests for sorting * Refactor: Changes according to PR comments * Refactor: Changes according to PR comments * Refactor: Moves Logs and ExploreGraphPanel out of grafana/ui * Fix: Shows the Show context label again
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import xss from 'xss';
|
|
|
|
const XSSWL = Object.keys(xss.whiteList).reduce((acc, element) => {
|
|
// @ts-ignore
|
|
acc[element] = xss.whiteList[element].concat(['class', 'style']);
|
|
return acc;
|
|
}, {});
|
|
|
|
const sanitizeXSS = new xss.FilterXSS({
|
|
whiteList: XSSWL,
|
|
});
|
|
|
|
/**
|
|
* Returns string safe from XSS attacks.
|
|
*
|
|
* Even though we allow the style-attribute, there's still default filtering applied to it
|
|
* Info: https://github.com/leizongmin/js-xss#customize-css-filter
|
|
* Whitelist: https://github.com/leizongmin/js-css-filter/blob/master/lib/default.js
|
|
*/
|
|
export function sanitize(unsanitizedString: string): string {
|
|
try {
|
|
return sanitizeXSS.process(unsanitizedString);
|
|
} catch (error) {
|
|
console.log('String could not be sanitized', unsanitizedString);
|
|
return unsanitizedString;
|
|
}
|
|
}
|
|
|
|
export function hasAnsiCodes(input: string): boolean {
|
|
return /\u001b\[\d{1,2}m/.test(input);
|
|
}
|
|
|
|
export function escapeHtml(str: string): string {
|
|
return String(str)
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"');
|
|
}
|