Commit 62889dd7 authored by Mark Florian's avatar Mark Florian

Fix isRootRelative for protocol-relative URLs

Protocol-relative URLs, e.g., `//foo.test`, are not root-relative. This
fixes `isRootRelative` to return `false` when given a protocol-relative
URL using a negative lookahead assertion for a second '/' character.
parent 3ca021ae
...@@ -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