Skip to content

Commit f5c9efd

Browse files
fix: updating regex url testing function
using something similar to whats found in loader-utils
1 parent 19e6722 commit f5c9efd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/hmr/hotModuleReplacement.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function updateCss(el, url) {
9090
url = el.href.split('?')[0];
9191
}
9292

93-
if (isDataURL(url)) {
93+
if (!isUrlRequest(url)) {
9494
return;
9595
}
9696

@@ -147,7 +147,7 @@ function reloadStyle(src) {
147147
forEach.call(elements, function(el) {
148148
var url = getReloadUrl(el.href, src);
149149

150-
if (isDataURL(url)) {
150+
if (!isUrlRequest(url)) {
151151
return;
152152
}
153153

@@ -176,11 +176,25 @@ function reloadAll() {
176176
});
177177
}
178178

179-
function isDataURL(s) {
180-
return !!s.match(
181-
// eslint-disable-next-line no-useless-escape
182-
/^\s*data:([a-z]+\/[a-z0-9-+.]+(;[a-z-]+=[a-z0-9-]+)?)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s]*)\s*$/i
183-
);
179+
function isUrlRequest(url) {
180+
// An URL is not an request if
181+
182+
// 1. It's an absolute url
183+
if (/^[a-z][a-z0-9+.-]*:/i.test(url)) {
184+
return false;
185+
}
186+
187+
// 2. It's a protocol-relative
188+
if (/^\/\//.test(url)) {
189+
return false;
190+
}
191+
192+
// 3. Its a `#` link
193+
if (/^#/.test(url)) {
194+
return false;
195+
}
196+
197+
return true;
184198
}
185199

186200
module.exports = function(moduleId, options) {

0 commit comments

Comments
 (0)