diff --git a/lib/helpers/parseProtocol.js b/lib/helpers/parseProtocol.js index 1ad6658c..05a2d6d2 100644 --- a/lib/helpers/parseProtocol.js +++ b/lib/helpers/parseProtocol.js @@ -1,6 +1,6 @@ 'use strict'; export default function parseProtocol(url) { - const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); + const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url); return (match && match[1]) || ''; } diff --git a/tests/unit/parseProtocol.test.js b/tests/unit/parseProtocol.test.js index 6a295f36..ec546efe 100644 --- a/tests/unit/parseProtocol.test.js +++ b/tests/unit/parseProtocol.test.js @@ -25,4 +25,8 @@ describe('helpers::parseProtocol', () => { } ); }); + + it('should not match URLs without a colon separator', () => { + assert.strictEqual(parseProtocol('http//example.com'), ''); + }); });