From a876ff48ebf93ba6dca95603c0446043206f48d0 Mon Sep 17 00:00:00 2001 From: Constantin Miron Date: Mon, 8 Mar 2021 23:28:38 +0200 Subject: [PATCH] fix(autoload): Colon after protocol (#65) If protocol is explicitly specified, ensure a colon is added. --- index.js | 4 +++- test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 844a0c6..b820806 100755 --- a/index.js +++ b/index.js @@ -176,6 +176,8 @@ class LiveReloadPlugin { * @private */ _autoloadJs() { + const protocol = this.options.protocol; + const fullProtocol = `${protocol}${protocol ? ':' : ''}` return ( ` // webpack-livereload-plugin @@ -186,7 +188,7 @@ class LiveReloadPlugin { var el = document.createElement("script"); el.id = id; el.async = true; - el.src = "${this.options.protocol}//${this.options.hostname}:${this.options.port}/livereload.js"; + el.src = "${fullProtocol}//${this.options.hostname}:${this.options.port}/livereload.js"; document.getElementsByTagName("head")[0].appendChild(el); console.log("[Live Reload] enabled"); }()); diff --git a/test.js b/test.js index 5c5d495..f829871 100644 --- a/test.js +++ b/test.js @@ -260,3 +260,19 @@ test('autoloadJs contains instanceId', function(t) { t.end(); }); +test('autoloadJs suffixes protocol with colon', function(t) { + const plugin = new LiveReloadPlugin({ + protocol: 'https' + }); + const [,src] = plugin._autoloadJs().match(/src\s+=\s+"(.+)"/) + t.assert(src.startsWith('https://')); + t.end(); +}); + + +test('autoloadJs suffixes empty protocol without colon', function(t) { + const plugin = new LiveReloadPlugin(); + const [,src] = plugin._autoloadJs().match(/src\s+=\s+"(.+)"/) + t.assert(src.startsWith('//')); + t.end(); +}); \ No newline at end of file