Skip to content

Commit

Permalink
ResourceFilterList.negateFilters: Always prefix includes with '+'
Browse files Browse the repository at this point in the history
This prevents potential misinterpretation of paths that start with +, -
or !

Calling negatFilters an even number of times will give now always return
a value that is semantically equal to the initial input.
  • Loading branch information
RandomByte committed Feb 8, 2021
1 parent 852622a commit 3f4624b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/lbt/resources/ResourceFilterList.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ResourceFilterList.negateFilters = function(patterns) {
return "!" + pattern;
} else {
// exclude => include
return pattern;
return "+" + pattern;
}
});
};
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function({
// Add configured excludes for namespace
allFilterExcludes.forEach((filterExclude) => {
// Allow all excludes and limit re-includes to the component namespace
if (filterExclude.startsWith("!") || filterExclude.startsWith(`${namespace}/`)) {
if (filterExclude.startsWith("!") || filterExclude.startsWith(`+${namespace}/`)) {
filters.push(filterExclude);
unusedFilterExcludes.delete(filterExclude);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ module.exports = function({
if (unusedFilterExcludes.size > 0) {
unusedFilterExcludes.forEach((filterExclude) => {
log.warn(
`Configured preload exclude contains invalid re-include: !${filterExclude}. ` +
`Configured preload exclude contains invalid re-include: !${filterExclude.substr(1)}. ` +
`Re-includes must start with a component namespace (${allNamespaces.join(" or ")})`
);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ function getDefaultLibraryPreloadFilters(namespace, excludes) {
// Add configured excludes at the end of filter list
allFilterExcludes.forEach((filterExclude) => {
// Allow all excludes and limit re-includes to the library namespace
if (filterExclude.startsWith("!") || filterExclude.startsWith(`${namespace}/`)) {
if (filterExclude.startsWith("!") || filterExclude.startsWith(`+${namespace}/`)) {
filters.push(filterExclude);
} else {
log.warn(`Configured preload exclude contains invalid re-include: !${filterExclude}. ` +
log.warn(`Configured preload exclude contains invalid re-include: !${filterExclude.substr(1)}. ` +
`Re-includes must start with the library's namespace ${namespace}`);
}
});
Expand Down
12 changes: 6 additions & 6 deletions test/lib/tasks/bundlers/generateComponentPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ test.serial("generateComponentPreload - one namespace - excludes", async (t) =>
"!my/app/test/",
"!my/app/*.html",
"!my/app/thirdparty/",
"my/app/thirdparty/NotExcluded.js"
"+my/app/thirdparty/NotExcluded.js"
],
mode: "preload",
renderer: false,
Expand Down Expand Up @@ -237,7 +237,7 @@ test.serial("generateComponentPreload - multiple namespaces - excludes", async (
"!my/app1/test/",
"!my/app1/*.html",
"!my/app1/thirdparty1/",
"my/app1/thirdparty1/NotExcluded.js",
"+my/app1/thirdparty1/NotExcluded.js",
"!my/app2/thirdparty2/",
],
mode: "preload",
Expand Down Expand Up @@ -273,7 +273,7 @@ test.serial("generateComponentPreload - multiple namespaces - excludes", async (
"!my/app2/*.html",
"!my/app1/thirdparty1/",
"!my/app2/thirdparty2/",
"my/app2/thirdparty2/NotExcluded.js"
"+my/app2/thirdparty2/NotExcluded.js"
],
mode: "preload",
renderer: false,
Expand Down Expand Up @@ -441,8 +441,8 @@ test.serial("generateComponentPreload - nested namespaces - excludes", async (t)

// via excludes config
"!my/project/component1/foo/",
"my/project/test/",
"my/project/component2/*.html",
"+my/project/test/",
"+my/project/component2/*.html",

// sub-namespaces are excluded
"!my/project/component1/",
Expand Down Expand Up @@ -482,7 +482,7 @@ test.serial("generateComponentPreload - nested namespaces - excludes", async (t)

// via excludes config
"!my/project/component1/foo/",
"my/project/component2/*.html"
"+my/project/component2/*.html"
],
mode: "preload",
renderer: false,
Expand Down
2 changes: 1 addition & 1 deletion test/lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ test.serial("generateLibraryPreload with excludes", async (t) => {

// via excludes option
"!my/lib/thirdparty/",
"my/lib/thirdparty/NotExcluded.js"
"+my/lib/thirdparty/NotExcluded.js"
],
mode: "preload",
renderer: true,
Expand Down

0 comments on commit 3f4624b

Please sign in to comment.