Skip to content

Commit

Permalink
Fixes Jeager UI broken when accessing via IPv6 address (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Mahesh PAI R <mahesh.pai_r@nokia.com>
  • Loading branch information
Mahesh PAI R committed Dec 5, 2019
1 parent 0c175e1 commit cb3f39e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
19 changes: 18 additions & 1 deletion packages/jaeger-ui/src/utils/prefix-url.test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

jest.mock('../site-prefix', () => `${global.location.origin}/a/site/prefix/`);

import prefixUrl from './prefix-url';
import prefixUrl, { regExEscape } from './prefix-url';

const PATH_PREFIX = '/a/site/prefix';
const IPV6_HOST_ADDRESS = '2a00:8a00:4000:751e::1c';

describe('prefixUrl()', () => {
const tests = [
Expand All @@ -37,3 +38,19 @@ describe('prefixUrl()', () => {
});
});
});

describe('regExEscape()', () => {
const tests = [
{ source: undefined, target: '' },
{ source: null, target: '' },
{ source: `${IPV6_HOST_ADDRESS}`, target: `${IPV6_HOST_ADDRESS}` },
{ source: `[${IPV6_HOST_ADDRESS}]`, target: `\\[${IPV6_HOST_ADDRESS}\\]` },
{ source: `[${IPV6_HOST_ADDRESS}]:8080`, target: `\\[${IPV6_HOST_ADDRESS}\\]:8080` },
];

tests.forEach(({ source, target }) => {
it(`regexEscape "${source}" correctly`, () => {
expect(regExEscape(source)).toBe(target);
});
});
});
13 changes: 12 additions & 1 deletion packages/jaeger-ui/src/utils/prefix-url.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
export 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
Expand All @@ -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, '');

/**
Expand Down

0 comments on commit cb3f39e

Please sign in to comment.