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 = ` Mattermost

Cannot connect to Mattermost


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.


` +const contentSecurityPolicyNotFoundHTML = ` Mattermost <

Cannot connect to Mattermost


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.


` -const contentSecurityPolicyNotFound2HTML = ` Mattermost

Cannot connect to Mattermost


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.


` +const contentSecurityPolicyNotFound2HTML = ` Mattermost

Cannot connect to Mattermost


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.


` -const baseRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` +const baseRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` const baseCSS = `@font-face{font-family:FontAwesome;src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` -const subpathRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` +const subpathRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` const subpathCSS = `@font-face{font-family:FontAwesome;src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` -const newSubpathRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` +const newSubpathRootHTML = ` Mattermost

Cannot connect to Mattermost


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.


` const newSubpathCSS = `@font-face{font-family:FontAwesome;src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot);src:url(/nested/subpath/static/files/674f50d287a8c48dc19ba404d20fe713.eot?#iefix&v=4.7.0) format("embedded-opentype"),url(/nested/subpath/static/files/af7ae505a9eed503f8b8e6982036873e.woff2) format("woff2"),url(/nested/subpath/static/files/fee66e712a8a08eef5805a46892932ad.woff) format("woff"),url(/nested/subpath/static/files/b06871f281fee6b241d60582ae9369b9.ttf) format("truetype"),url(/nested/subpath/static/files/677433a0892aaed7b7d2628c313c9775.svg#fontawesomeregular) format("svg");font-weight:400;font-style:normal}` diff --git a/webapp/channels/src/root.html b/webapp/channels/src/root.html index 0f615ca0801..a6f59ef19d2 100644 --- a/webapp/channels/src/root.html +++ b/webapp/channels/src/root.html @@ -19,11 +19,14 @@ + + +