From 1919ad1b62efe430b566b368bdeb27adaff2505d Mon Sep 17 00:00:00 2001 From: vargajoe Date: Fri, 25 Mar 2022 20:47:13 +0100 Subject: [PATCH 1/4] fix broken action on content name w parenthesis --- packages/sn-client-utils/src/path-helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index f0a8c4c4a..122063dab 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -48,7 +48,7 @@ export class PathHelper { * @param segment The segment to be examined */ public static isItemSegment(segment: string): boolean { - return RegExp(/\('+[\s\S]+'\)$/).test(segment) || RegExp(/\(+\w+\d+\)$/).test(segment) + return RegExp(/^\('+[\s\S]+'\)$/).test(segment) || RegExp(/^\(+\w+\d+\)$/).test(segment) } /** From 77bc86fae4e672e89b899dfa08342af82502c534 Mon Sep 17 00:00:00 2001 From: vargajoe Date: Tue, 29 Mar 2022 00:13:16 +0200 Subject: [PATCH 2/4] remove unnecessary regex - nums not itemsegments --- packages/sn-client-utils/src/path-helper.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index 122063dab..842a1309c 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -33,7 +33,7 @@ export class PathHelper { if (!lastItem) { throw new Error(`Couldn't get the segments for ${path}`) } - // Match if last item is Root/content(123) or Root/Example('content') + // Match if last item is Root/Example('content') const matches = lastItem.match(/(\('\w+'\)$)/g) if (!matches) { return [...splitted, lastItem] @@ -44,11 +44,11 @@ export class PathHelper { } /** - * Checks if a specific segment is an Item segment or not (like "('Content1')" or "Test(1)") + * Checks if a specific segment is an Item segment or not (like "('Content1')") * @param segment The segment to be examined */ public static isItemSegment(segment: string): boolean { - return RegExp(/^\('+[\s\S]+'\)$/).test(segment) || RegExp(/^\(+\w+\d+\)$/).test(segment) + return RegExp(/^\('+[\s\S]+'\)$/).test(segment) } /** From 293168437b4d072e8a4eacb19905cc1dabf09cd3 Mon Sep 17 00:00:00 2001 From: vargajoe Date: Tue, 29 Mar 2022 10:51:19 +0200 Subject: [PATCH 3/4] normalize getsegment rx with itemsegment rx remove faulty test logics --- packages/sn-client-utils/src/path-helper.ts | 4 ++-- packages/sn-client-utils/test/path-helper.test.ts | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index 842a1309c..b82f9ae5b 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -34,7 +34,7 @@ export class PathHelper { throw new Error(`Couldn't get the segments for ${path}`) } // Match if last item is Root/Example('content') - const matches = lastItem.match(/(\('\w+'\)$)/g) + const matches = lastItem.match(/(\('[\s\S]+'\)$)/g) if (!matches) { return [...splitted, lastItem] } @@ -48,7 +48,7 @@ export class PathHelper { * @param segment The segment to be examined */ public static isItemSegment(segment: string): boolean { - return RegExp(/^\('+[\s\S]+'\)$/).test(segment) + return RegExp(/\('[\s\S]+'\)$/).test(segment) } /** diff --git a/packages/sn-client-utils/test/path-helper.test.ts b/packages/sn-client-utils/test/path-helper.test.ts index ee9a5f50b..50e91f806 100644 --- a/packages/sn-client-utils/test/path-helper.test.ts +++ b/packages/sn-client-utils/test/path-helper.test.ts @@ -9,10 +9,6 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.isItemSegment("('Item1')")).toBe(true) }) - it('Should return true for item segments with numeric key "(42)"', () => { - expect(PathHelper.isItemSegment('(42)')).toBe(true) - }) - it('Should return false for string keys w/o quotes', () => { expect(PathHelper.isItemSegment('(invalidValue)')).toBe(false) }) @@ -63,11 +59,6 @@ export const pathHelperTests = describe('PathHelper', () => { const isAnItem = PathHelper.isItemPath("/workspace/('project')/CustomAction") expect(isAnItem).toBe(true) }) - - it('should return true for reference paths with ids', () => { - const isAnItem = PathHelper.isItemPath('/workspaces/(22)/CustomAction') - expect(isAnItem).toBe(true) - }) }) describe('#getContentUrlbyId()', () => { @@ -202,6 +193,10 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.getParentPath('Root/Memo/Test(1)')).toBe('Root/Memo') }) + it('Should return the parent path in case of more than 1 segments with item path', () => { + expect(PathHelper.getParentPath('Root/Memo/Test (11)')).toBe('Root/Memo') + }) + it('Should return the path in case of 1 segments', () => { expect(PathHelper.getParentPath('Root')).toBe('Root') }) From da336ee16662128749f215dd394d6d46ea24c1d6 Mon Sep 17 00:00:00 2001 From: vargajoe Date: Thu, 9 Jun 2022 15:59:32 +0200 Subject: [PATCH 4/4] mod path helper segment regex --- packages/sn-client-utils/src/path-helper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index b82f9ae5b..f95029786 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -34,7 +34,7 @@ export class PathHelper { throw new Error(`Couldn't get the segments for ${path}`) } // Match if last item is Root/Example('content') - const matches = lastItem.match(/(\('[\s\S]+'\)$)/g) + const matches = lastItem.match(/(\('.+'\)$)/g) if (!matches) { return [...splitted, lastItem] } @@ -48,7 +48,7 @@ export class PathHelper { * @param segment The segment to be examined */ public static isItemSegment(segment: string): boolean { - return RegExp(/\('[\s\S]+'\)$/).test(segment) + return RegExp(/\('.+'\)$/).test(segment) } /**