MM-57839: Rewrite static assets only if needed (#27076)
* Rewrite static assets only if needed
Refactor UpdateAssetsSubpathInDir so that the actual rewriting of files
happen in two different functions: one for root.html, another for
manifest.json and *.css files.
I would have wanted to simply do a
if pathToReplace == newPath { return nil }
when those two variables are defined, but the logic for root.html is not
that simple, and that may miss some edge cases, so I opted out for
simply moving the actual rewriting to individual functions, which check
for their corresponding conditions to perform the update:
1. for root.html, check that the edited file is indeed different than
the original one
2. for manifest.json and *.css files, rewrite them only if
pathToReplace != newPath, which in this case is clear that that's the
only modification we do
* Fix expected error msg in test
---------
Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bf8ddb4bdc
Коммит
d81ce03168
@@ -109,7 +109,7 @@ func TestUpdateAssetsSubpath(t *testing.T) {
|
||||
baseCSS,
|
||||
baseManifestJSON,
|
||||
"/subpath",
|
||||
fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite"),
|
||||
fmt.Errorf("failed to update root.html: %w", fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite")),
|
||||
contentSecurityPolicyNotFoundHTML,
|
||||
baseCSS,
|
||||
baseManifestJSON,
|
||||
@@ -120,7 +120,7 @@ func TestUpdateAssetsSubpath(t *testing.T) {
|
||||
baseCSS,
|
||||
baseManifestJSON,
|
||||
"/subpath",
|
||||
fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite"),
|
||||
fmt.Errorf("failed to update root.html: %w", fmt.Errorf("failed to find 'Content-Security-Policy' meta tag to rewrite")),
|
||||
contentSecurityPolicyNotFound2HTML,
|
||||
baseCSS,
|
||||
baseManifestJSON,
|
||||
|
||||
Ссылка в новой задаче
Block a user