This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ACS-4724] remove minimatch dependency (#1536)
* ACS-4724 Removed minimatch dependency * ACS-4724 Updated package-lock json file
- Loading branch information
1 parent
a7c0cee
commit 2414d22
Showing
8 changed files
with
128 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export class PathMatcher { | ||
static match(path: string, pattern: string) { | ||
return new RegExp( | ||
`^${ | ||
pattern | ||
.replace(/(^|[^\*])\*(?!\*)/g, '$1([^\\/]*)') | ||
.replace(/\/\*\*\//g, '/(.+)/|/') | ||
.replace(/\*\*/g, '(.*)') | ||
}$` | ||
).test(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { PathMatcher } from '../src/utils/path-matcher'; | ||
|
||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
|
||
describe('PathMatcher', () => { | ||
describe('match', () => { | ||
it('should return true if path is exactly the same like pattern', () => { | ||
expect(PathMatcher.match('public-url', 'public-url')).be.true; | ||
}); | ||
|
||
it('should return false if path is not equal to pattern', () => { | ||
expect(PathMatcher.match('some-public-url', 'public-url')).be.false; | ||
}); | ||
|
||
it('should return true if absolute path is equal to absolute path', () => { | ||
expect(PathMatcher.match('http://some-public-url', 'http://some-public-url')).be.true; | ||
}); | ||
|
||
it('should return true if path matches pattern containing double and single *', () => { | ||
expect(PathMatcher.match('http://some-public-url/123/path', '**/some-public-url/*/path')).be.true; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => { | ||
expect(PathMatcher.match('http://test/other-test/some-public-url/path', '**/some-public-url/path')).be.true; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => { | ||
expect(PathMatcher.match('http://test/other-test/some-public-url/path', '**/some-public-url/path')).be.true; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with multiple parts at the end', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/**')).be.true; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with none parts at the end', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/', 'http://some-public-url/path/**')).be.true; | ||
}); | ||
|
||
it('should return false if path does not match to pattern after replacing ** with none parts at the end and cuts last /', () => { | ||
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/path/**')).be.false; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with multiple parts in the middle', () => { | ||
expect(PathMatcher.match('http://some-public-url/test/other-test/path', 'http://some-public-url/**/path')).be.true; | ||
}); | ||
|
||
it('should return true if path matches to pattern after replacing ** with none parts in the middle', () => { | ||
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/**/path')).be.true; | ||
}); | ||
|
||
it('should return false if path does not match to pattern with **', () => { | ||
expect(PathMatcher.match('http://some-public-url/', 'http://some-public-url/**/path')).be.false; | ||
}); | ||
|
||
it('should return false if path has more than one part as replacement for * in the middle of pattern', () => { | ||
expect(PathMatcher.match('http://some-public-url/123/test/path', 'http://some-public-url/*/path')).be.false; | ||
}); | ||
|
||
it('should return false if path has zero parts as replacement for * in the middle of pattern', () => { | ||
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/*/path')).be.false; | ||
}); | ||
|
||
it('should return true if path matches to pattern containing * at the end', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/test', 'http://some-public-url/path/*')).be.true; | ||
}); | ||
|
||
it('should return false if path matches to pattern containing * at the end and cuts last /', () => { | ||
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/path/*')).be.false; | ||
}); | ||
|
||
it('should return false if path has more than one part as replacement for * at the end of pattern', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/*')).be.false; | ||
}); | ||
|
||
it('should return false if path has zero parts as replacement for * at the end of pattern', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/*')).be.false; | ||
}); | ||
|
||
it('should return false if path starts with http:// and * is at the beginning of pattern', () => { | ||
expect(PathMatcher.match('http://some-public-url/path/test', '*/some-public-url/path')).be.false; | ||
}); | ||
}); | ||
}); |