diff --git a/lib/runner/util.js b/lib/runner/util.js index 4ef8ba62f..eeb75d88c 100644 --- a/lib/runner/util.js +++ b/lib/runner/util.js @@ -198,10 +198,16 @@ module.exports = { // convert the domains to UrlMatchPattern variable._.domainPatterns = new UrlMatchPatternList(null, domains.map((domain) => { - const url = new Url(domain); + const url = new Url(domain), + + // Get the host without port + hostWithoutPort = url.getRemote().replace(/:\d+$/, ''), + + // Create a pattern that matches with or without port + hostPattern = `${hostWithoutPort}(:\\d+)?`; // @note URL path is ignored - return `${url.protocol || 'https'}://${url.getRemote()}/*`; + return `${url.protocol || 'https'}://${hostPattern}/*`; })); }); @@ -219,16 +225,15 @@ module.exports = { return scope.values; } - const urlWithoutPort = urlString.replace(/:\d+/, ''), - variables = scope.values.filter((variable) => { - const domainPatterns = variable && variable._ && variable._.domainPatterns; + const variables = scope.values.filter((variable) => { + const domainPatterns = variable && variable._ && variable._.domainPatterns; - if (!domainPatterns) { - return true; - } + if (!domainPatterns) { + return true; + } - return domainPatterns.test(urlWithoutPort); - }); + return domainPatterns.test(urlString); + }); return new VariableList(null, variables.map((variable) => { return variable.toJSON(); // clone the variable