Skip to content

Commit

Permalink
Fixes no-restricted-path false-positives when allowSameFolder is …
Browse files Browse the repository at this point in the history
…true (#3020)

`no-restricted-paths` compares source files and import statements, and their membership in restricted zones. However, when `allowSameFolder` is true, it failed to remove a trailing slash before validation which results in a false-positive.

Signed-off-by: Miki <[email protected]>

Signed-off-by: Miki <[email protected]>
(cherry picked from commit 8732b1c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
github-actions[bot] authored and AMoo-Miki committed Dec 22, 2022
1 parent 744c083 commit 692af42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function traverseToTopFolder(src, pattern) {
const srcIdx = src.lastIndexOf(path.sep);
src = src.slice(0, srcIdx);
}
return src.replace(/\\/g, '/');
return src.replace(/\\/g, '/').replace(/\/$/, '');
}

function isSameFolderOrDescendent(src, imported, pattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ ruleTester.run('@osd/eslint/no-restricted-paths', rule, {
},
],
},
{
code: 'import b from "testfiles/no_restricted_paths/server/deep/deeper/e.js"',
filename: path.join(__dirname, 'testfiles/no_restricted_paths/server/deep/d.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'testfiles/**/server/**/*',
from: 'testfiles/**/server/**/*',
allowSameFolder: true,
},
],
},
],
},

// irrelevant function calls
{
Expand Down

0 comments on commit 692af42

Please sign in to comment.