diff --git a/server/channels/utils/subpath.go b/server/channels/utils/subpath.go index d1999c5cec6..ec1cc44b3e6 100644 --- a/server/channels/utils/subpath.go +++ b/server/channels/utils/subpath.go @@ -113,15 +113,15 @@ func updateRootFile(oldRootHTML string, rootHTMLPath string, alreadyRewritten bo // be updated (and isn't covered by the cases above). newRootHTML = strings.Replace(newRootHTML, pathToReplace, newPath, -1) + publicPathInWindowsScriptRegex := regexp.MustCompile(`(?s)`) + if alreadyRewritten && subpath == "/" { - // Remove the injected script since no longer required. Note that the rewrite above - // will have affected the script, so look for the new subpath, not the old one. - oldScript := getSubpathScript(subpath) - newRootHTML = strings.Replace(newRootHTML, fmt.Sprintf("", oldScript), "", 1) + // Remove window global publicPath definition if subpath is root + newRootHTML = publicPathInWindowsScriptRegex.ReplaceAllLiteralString(newRootHTML, "") } else if !alreadyRewritten && subpath != "/" { - // Otherwise, inject the script to define `window.publicPath`. - script := getSubpathScript(subpath) - newRootHTML = strings.Replace(newRootHTML, "", fmt.Sprintf("", script), 1) + // Inject the script to define `window.publicPath` for the specified subpath + subpathScript := getSubpathScript(subpath) + newRootHTML = publicPathInWindowsScriptRegex.ReplaceAllLiteralString(newRootHTML, fmt.Sprintf("", subpathScript)) } if newRootHTML == oldRootHTML { diff --git a/server/channels/utils/subpath_test.go b/server/channels/utils/subpath_test.go index fcdee12742b..3b6b69e8731 100644 --- a/server/channels/utils/subpath_test.go +++ b/server/channels/utils/subpath_test.go @@ -267,19 +267,19 @@ func sToP(s string) *string { return &s } -const contentSecurityPolicyNotFoundHTML = `
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.
We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.