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]>
  • Loading branch information
AMoo-Miki authored Dec 8, 2022
1 parent a26fb43 commit 8732b1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BWC Tests] Add BWC tests for 2.5.0 ([#2890](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2890))
- Fix incorrect validation of time values in JUnit Reporter ([#2965](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2965))
- Make tests covering plugin installation on cluster snapshots work across platforms ([#2994](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2994))
- Correct the linting logic for `no-restricted-path` to ignore trailing slashes ([#3020](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3020))

## [2.x]

Expand Down
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 8732b1c

Please sign in to comment.