Skip to content

Commit

Permalink
feat: replace picomatch with minimatch (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
nodece committed Mar 20, 2023
1 parent 9c42b9c commit 4e977b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"buffer": "^6.0.3",
"csv-parse": "^5.3.5",
"expression-eval": "^5.0.0",
"picomatch": "^2.2.3"
"minimatch": "^7.4.2"
},
"files": [
"lib",
Expand Down
9 changes: 7 additions & 2 deletions src/util/builtinOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as rbac from '../rbac';
import { ip } from './ip';
import { isMatch } from 'picomatch';
import { minimatch } from 'minimatch';

// regexMatch determines whether key1 matches the pattern of key2 in regular expression.
function regexMatch(key1: string, key2: string): boolean {
Expand Down Expand Up @@ -305,7 +305,12 @@ function ipMatchFunc(...args: any[]): boolean {
* ```
*/
function globMatch(string: string, pattern: string): boolean {
return isMatch(string, pattern);
// The minimatch doesn't support the pattern starts with *
// See https://github.com/isaacs/minimatch/issues/195
if (pattern[0] === '*' && pattern[1] === '/') {
pattern = pattern.substring(1);
}
return minimatch(string, pattern);
}

// generateGFunction is the factory method of the g(_, _) function.
Expand Down
2 changes: 2 additions & 0 deletions test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ test('test globMatch', () => {
expect(util.globMatch('/prefix/subprefix/foobar', '*/foo')).toEqual(false);
expect(util.globMatch('/prefix/subprefix/foobar', '*/foo*')).toEqual(false);
expect(util.globMatch('/prefix/subprefix/foobar', '*/foo/*')).toEqual(false);

expect(util.globMatch('a.conf', '*.conf')).toEqual(true);
});

test('test hasEval', () => {
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,13 @@ brace-expansion@^1.1.7:
balanced-match "^1.0.0"
concat-map "0.0.1"

brace-expansion@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae"
integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==
dependencies:
balanced-match "^1.0.0"

braces@^2.3.1:
version "2.3.2"
resolved "https://registry.npmjs.org/braces/-/braces-2.3.2.tgz#5979fd3f14cd531565e5fa2df1abfff1dfaee729"
Expand Down Expand Up @@ -5270,6 +5277,13 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"

minimatch@^7.4.2:
version "7.4.2"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-7.4.2.tgz#157e847d79ca671054253b840656720cb733f10f"
integrity sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==
dependencies:
brace-expansion "^2.0.1"

minimist-options@4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/minimist-options/-/minimist-options-4.1.0.tgz#c0655713c53a8a2ebd77ffa247d342c40f010619"
Expand Down

0 comments on commit 4e977b3

Please sign in to comment.