From 1e491579c1463c2444dbc78ce81ee3dd4ae3172a Mon Sep 17 00:00:00 2001 From: Jaco Date: Sat, 9 Oct 2021 15:49:01 +0300 Subject: [PATCH] Adjust wildcard path matches (#4040) --- .../PortableRegistry/PortableRegistry.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/types/src/generic/PortableRegistry/PortableRegistry.ts b/packages/types/src/generic/PortableRegistry/PortableRegistry.ts index 88baf23251..60d3e0b486 100644 --- a/packages/types/src/generic/PortableRegistry/PortableRegistry.ts +++ b/packages/types/src/generic/PortableRegistry/PortableRegistry.ts @@ -57,12 +57,25 @@ function matchParts (first: string[], second: (string | Text)[]): boolean { return first.length === second.length && first.every((a, index) => { const b = second[index].toString(); - return (a === '*') || (a === b) || ( - a.includes('*') && - a.includes('_') && - b.includes('_') && - matchParts(a.split('_'), b.split('_')) - ); + if ((a === '*') || (a === b)) { + return true; + } + + if (a.includes('*') && a.includes('_') && b.includes('_')) { + const suba = a.split('_'); + const subb = b.split('_'); + + if (suba[0] === '*') { + // the first parts where the length is greater is always a match + while (suba.length < subb.length) { + subb.shift(); + } + } + + return matchParts(suba, subb); + } + + return false; }); }