Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Fixes no-restricted-path false-positives when allowSameFolder is …
Browse files Browse the repository at this point in the history
…true (opensearch-project#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 <amoo_miki@yahoo.com>

Signed-off-by: Miki <amoo_miki@yahoo.com>
Signed-off-by: David Sinclair <david@sinclair.tech>
  • Loading branch information
AMoo-Miki authored and sikhote committed Apr 24, 2023
1 parent cdbe6e6 commit d3ed3eb
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 d3ed3eb

Please sign in to comment.