Compare commits

...

10 Commits

Author SHA1 Message Date
Oscar Kilhed
fb85ed6912 Merge pull request #147 from grafana/axelav/sanitized-nav-links-8-2-3
Sanitized NavBar children links to remove angular interpolation v8.2.3
2021-10-25 09:45:05 +02:00
Dimitris Sotirakis
3cb5214fa4 Merge pull request #151 from grafana/dcech/sanitize-replaceAll
use global replace when sanitizing urls in 8.2.3
2021-10-25 10:16:51 +03:00
Dan Cech
1c7ce348ce switch to global regexp 2021-10-22 16:40:45 -04:00
Dan Cech
8081dc9ee9 use replaceAll when sanitizing urls 2021-10-22 15:23:06 -04:00
Alexandra Vargas
a3dc30546f NavBar: Add sanitize to children items 2021-10-22 17:40:31 +02:00
Dimitris Sotirakis
31b78d51c6 Merge pull request #146 from grafana/oscark/sanitize-nav-links
Sanitized nav bar links to remove angular interpolation
2021-10-22 17:36:10 +03:00
Oscar Kilhed
0b440d5381 Revert "Angular: Fix for paths with interpolation"
This reverts commit 5c7224eb56.
2021-10-22 16:16:40 +02:00
Oscar Kilhed
34eda6123d Sanitized nav bar links to remove angular interpolation 2021-10-22 16:14:24 +02:00
Dimitris Sotirakis
e804e3847b Merge pull request #145 from grafana/8.2.3-angular-fix
8.2.3 angular fix
2021-10-22 16:20:25 +03:00
Hugo Häggmark
5c7224eb56 Angular: Fix for paths with interpolation 2021-10-22 14:44:54 +02:00
4 changed files with 17 additions and 9 deletions

View File

@@ -1,11 +1,12 @@
export * from './string';
export * from './markdown';
export * from './text';
import { escapeHtml, hasAnsiCodes, sanitize, sanitizeUrl } from './sanitize';
import { escapeHtml, hasAnsiCodes, sanitize, sanitizeUrl, sanitizeAngularInterpolation } from './sanitize';
export const textUtil = {
escapeHtml,
hasAnsiCodes,
sanitize,
sanitizeUrl,
sanitizeAngularInterpolation,
};

View File

@@ -38,3 +38,7 @@ export function hasAnsiCodes(input: string): boolean {
export function escapeHtml(str: string): string {
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}
export function sanitizeAngularInterpolation(url: string): string {
return url.replace(/\{\{/g, '%7B%7B').replace(/\}\}/g, '%7D%7D');
}

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data';
import { GrafanaTheme2, textUtil } from '@grafana/data';
import { Icon, IconName, Link, useTheme2 } from '@grafana/ui';
export interface Props {
@@ -29,13 +29,15 @@ const DropdownChild = ({ isDivider = false, icon, onClick, target, text, url }:
</button>
);
if (url) {
const sanitizedUrl = textUtil.sanitizeAngularInterpolation(url);
element =
!target && url.startsWith('/') ? (
<Link className={styles.element} onClick={onClick} href={url}>
<Link className={styles.element} onClick={onClick} href={sanitizedUrl}>
{linkContent}
</Link>
) : (
<a className={styles.element} href={url} target={target} rel="noopener" onClick={onClick}>
<a className={styles.element} href={sanitizedUrl} target={target} rel="noopener" onClick={onClick}>
{linkContent}
</a>
);

View File

@@ -1,6 +1,6 @@
import React, { ReactNode } from 'react';
import { css, cx } from '@emotion/css';
import { GrafanaTheme2, NavModelItem } from '@grafana/data';
import { GrafanaTheme2, NavModelItem, textUtil } from '@grafana/data';
import { Link, useTheme2 } from '@grafana/ui';
import NavBarDropdown from './NavBarDropdown';
@@ -34,13 +34,14 @@ const NavBarItem = ({
<span className={styles.icon}>{children}</span>
</button>
);
const sanitizedUrl = textUtil.sanitizeAngularInterpolation(url ?? '');
if (url) {
element =
!target && url.startsWith('/') ? (
!target && sanitizedUrl.startsWith('/') ? (
<Link
className={styles.element}
href={url}
href={sanitizedUrl}
target={target}
aria-label={label}
onClick={onClick}
@@ -49,7 +50,7 @@ const NavBarItem = ({
<span className={styles.icon}>{children}</span>
</Link>
) : (
<a href={url} target={target} className={styles.element} onClick={onClick} aria-label={label}>
<a href={sanitizedUrl} target={target} className={styles.element} onClick={onClick} aria-label={label}>
<span className={styles.icon}>{children}</span>
</a>
);
@@ -61,7 +62,7 @@ const NavBarItem = ({
<NavBarDropdown
headerTarget={target}
headerText={label}
headerUrl={url}
headerUrl={sanitizedUrl}
items={menuItems}
onHeaderClick={onClick}
reverseDirection={reverseMenuDirection}