diff --git a/packages/path/src/__tests__/match.spec.ts b/packages/path/src/__tests__/match.spec.ts index 2e77b090b06..6f01e322492 100644 --- a/packages/path/src/__tests__/match.spec.ts +++ b/packages/path/src/__tests__/match.spec.ts @@ -116,6 +116,11 @@ test('test group', () => { expect(node.match('phases.0.steps.1.type')).toBeTruthy() }) +test('test segments', () => { + const node = Path.parse('a.0.b') + expect(node.match(['a', 0, 'b'])).toEqual(true) +}) + match({ '*': [[], ['aa'], ['aa', 'bb', 'cc'], ['aa', 'dd', 'gg']], '*.a.b': [ diff --git a/packages/path/src/matcher.ts b/packages/path/src/matcher.ts index 5cb79f846d3..20d3946093e 100644 --- a/packages/path/src/matcher.ts +++ b/packages/path/src/matcher.ts @@ -18,7 +18,7 @@ import { RangeExpressionNode, DotOperatorNode, } from './types' -import { isEqual, toArr } from './shared' +import { isEqual, toArr, isSegmentEqual } from './shared' const isValid = (val) => val !== undefined && val !== null && val !== '' @@ -231,7 +231,7 @@ export class Matcher { if (source.length !== target.length) return false const match = (pos: number) => { const current = () => { - const res = isEqual(source[pos], target[pos]) + const res = isSegmentEqual(source[pos], target[pos]) if (record && record.score !== undefined) { record.score++ } diff --git a/packages/path/src/shared.ts b/packages/path/src/shared.ts index e45905bbf7d..c28f6e0f3d9 100644 --- a/packages/path/src/shared.ts +++ b/packages/path/src/shared.ts @@ -74,3 +74,8 @@ export const isEqual = (a: any, b: any) => { } return a !== a && b !== b } +export const isSegmentEqual = (a: any, b: any) => { + a = typeof a === 'symbol' ? a : `${a}` + b = typeof b === 'symbol' ? b : `${b}` + return a === b +}