diff --git a/packages/jaeger-ui/src/utils/prefix-url.tsx b/packages/jaeger-ui/src/utils/prefix-url.tsx index c2c1d44dcd..3753366e9f 100644 --- a/packages/jaeger-ui/src/utils/prefix-url.tsx +++ b/packages/jaeger-ui/src/utils/prefix-url.tsx @@ -14,6 +14,17 @@ import sitePrefix from '../site-prefix'; +/** + * Escape any RegEx characters in a given string + * + * @param {string} value The string which needs to be escaped + * @return {string} Escaped RegEx string + */ +function regExEscape(value?: string) { + const s = value == null ? '' : String(value); + return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); +}; + const origin = process.env.NODE_ENV === 'test' ? global.location.origin : window.location.origin; /** * Generate the URL prefix from `sitePrefix` and use it for all subsequent calls @@ -24,7 +35,7 @@ const origin = process.env.NODE_ENV === 'test' ? global.location.origin : window * - `"http://localhost:3000/abc/"` to `"/abc"` * - `"http://localhost:3000/abc/def/"` to `"/abc/def"` */ -const rx = new RegExp(`^${origin}|/$`, 'ig'); +const rx = new RegExp(`^${regExEscape(origin)}|/$`, 'ig'); const pathPrefix = sitePrefix.replace(rx, ''); /**