From 480636f967e3c5bcb8dab5f6a0e0783fcb318a8b Mon Sep 17 00:00:00 2001 From: Noritaka Kobayashi Date: Tue, 20 May 2025 19:36:59 +0900 Subject: [PATCH] refactor: use 'String#startsWith' & replace if-then-else --- lib/Server.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index e8af8c87a1..ff25797b34 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -3130,7 +3130,7 @@ class Server { // support "." as a subdomain wildcard // e.g. ".example.com" will allow "example.com", "www.example.com", "subdomain.example.com", etc - if (allowedHost[0] === ".") { + if (allowedHost.startsWith(".")) { // "example.com" (value === allowedHost.substring(1)) // "*.example.com" (value.endsWith(allowedHost)) if ( @@ -3217,12 +3217,7 @@ class Server { hostname.endsWith(".localhost") || hostname === this.options.host; - if (isValidHostname) { - return true; - } - - // disallow - return false; + return isValidHostname; } /**