Commit 13246d81 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'fix-root-relative-util' into 'master'

Fix isRootRelative for protocol-relative URLs

See merge request gitlab-org/gitlab!63884
parents 288e444b 62889dd7
...@@ -323,7 +323,7 @@ export function isAbsolute(url) { ...@@ -323,7 +323,7 @@ export function isAbsolute(url) {
* @param {String} url * @param {String} url
*/ */
export function isRootRelative(url) { export function isRootRelative(url) {
return /^\//.test(url); return /^\/(?!\/)/.test(url);
} }
/** /**
......
...@@ -471,6 +471,7 @@ describe('URL utility', () => { ...@@ -471,6 +471,7 @@ describe('URL utility', () => {
${'notaurl'} | ${false} ${'notaurl'} | ${false}
${'../relative_url'} | ${false} ${'../relative_url'} | ${false}
${'<a></a>'} | ${false} ${'<a></a>'} | ${false}
${'//other-host.test'} | ${false}
`('returns $valid for $url', ({ url, valid }) => { `('returns $valid for $url', ({ url, valid }) => {
expect(urlUtils.isRootRelative(url)).toBe(valid); expect(urlUtils.isRootRelative(url)).toBe(valid);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment