From 0c80007141b88aee98be698c2cb8effef63db689 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Thu, 13 Jul 2023 21:56:20 +0200 Subject: [PATCH] Use TrimPrefix instead of Replace --- render.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/render.go b/render.go index b179e71..cdf7809 100644 --- a/render.go +++ b/render.go @@ -55,10 +55,10 @@ func render(w http.ResponseWriter, r *http.Request) { // If the protocol is present strip it and redirect if strings.HasPrefix(code, "wss:/") || strings.HasPrefix(code, "ws:/") { hostname := code - hostname = strings.Replace(hostname, "wss://", "", 1) - hostname = strings.Replace(hostname, "ws://", "", 1) - hostname = strings.Replace(hostname, "wss:/", "", 1) // Some browsers replace upfront '//' with '/' - hostname = strings.Replace(hostname, "ws:/", "", 1) // Some browsers replace upfront '//' with '/' + hostname = strings.TrimPrefix(hostname, "wss://") + hostname = strings.TrimPrefix(hostname, "ws://") + hostname = strings.TrimPrefix(hostname, "wss:/") // Some browsers replace upfront '//' with '/' + hostname = strings.TrimPrefix(hostname, "ws:/") // Some browsers replace upfront '//' with '/' http.Redirect(w, r, "/"+hostname, http.StatusFound) }