Skip to content

Commit

Permalink
Fix: fix file system traversal of theme-loader to stop at root (#9505)
Browse files Browse the repository at this point in the history
The theme-loader recursion for themeFolder should stop
at the root level. Also if no theme folder found we should
not spend time on replacement.
  • Loading branch information
caalador committed Mar 1, 2021
1 parent 8c96d4f commit db1dc53
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"repository": "vaadin/flow",
"name": "@vaadin/theme-loader",
"version": "0.0.1",
"version": "0.0.2",
"main": "theme-loader.js",
"author": "Vaadin Ltd",
"license": "Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ module.exports = function (source, map) {
const logger = this.getLogger("theme-loader");

let themeFolder = handledResourceFolder;
while (themeFolder && path.basename(path.resolve(themeFolder, "..")) !== "theme") {
// Recurse up until we find the theme folder or don't have 'theme' on the path.
while (themeFolder.indexOf("theme") > 1
&& path.basename(path.resolve(themeFolder, "..")) !== "theme") {
themeFolder = path.resolve(themeFolder, "..");
}
// If we have found no theme folder return without doing anything.
if(path.basename(path.resolve(themeFolder, "..")) !== "theme") {
this.callback(null, source, map);
return;
}

logger.log("Using '", themeFolder, "' for the application theme base folder.");

source = source.replace(urlMatcher, function (match, url, quoteMark, replace, fileUrl, endString) {
Expand Down

0 comments on commit db1dc53

Please sign in to comment.