From 9b68f4e9fe12dd012e0260de37dc4aff958efd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enik=C5=91=20Pusztai?= Date: Fri, 25 Sep 2020 09:13:38 +0200 Subject: [PATCH 1/4] fix getParentPath with content name like Test(1) --- packages/sn-client-utils/src/path-helper.ts | 2 +- packages/sn-client-utils/test/path-helper.test.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index 389e674cf..3f69e2d18 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/content(123) or Root/Example('content') - const matches = lastItem.match(/(\('\w+'\)|\(\d+\)$)/g) + const matches = lastItem.match(/(\('\w+'\)$)/g) if (!matches) { return [...splitted, lastItem] } diff --git a/packages/sn-client-utils/test/path-helper.test.ts b/packages/sn-client-utils/test/path-helper.test.ts index d393f4471..684fb541a 100644 --- a/packages/sn-client-utils/test/path-helper.test.ts +++ b/packages/sn-client-utils/test/path-helper.test.ts @@ -173,11 +173,14 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.getSegments("/Root/Example('Content1')")).toEqual(['Root', 'Example', "('Content1')"]) }) it('Should split the path to segments', () => { - expect(PathHelper.getSegments('/Root/Example(123)')).toEqual(['Root', 'Example', '(123)']) + expect(PathHelper.getSegments('/Root/Example(123)')).toEqual(['Root', 'Example(123)']) }) it('Should split the path to segments', () => { expect(PathHelper.getSegments('/Root/Example/100pages(3).pdf')).toEqual(['Root', 'Example', '100pages(3).pdf']) }) + it('Should split the path to segments', () => { + expect(PathHelper.getSegments('/content(123)')).toEqual(['content(123)']) + }) it('should throw an error if the path is /', () => { expect(() => PathHelper.getSegments('/')).toThrow() }) @@ -195,6 +198,10 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.getParentPath("Root/Example('Content')")).toBe('Root/Example') }) + it('Should return the parent path in case of more than 1 segments with item path', () => { + expect(PathHelper.getParentPath('Root/Memo/Test(1)')).toBe('Root/Memo') + }) + it('Should return the path in case of 1 segments', () => { expect(PathHelper.getParentPath('Root')).toBe('Root') }) From f2780b966f6d79da7d1418fd6afd22cd951ac513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enik=C5=91=20Pusztai?= Date: Fri, 25 Sep 2020 16:29:45 +0200 Subject: [PATCH 2/4] fix isItemSegment --- 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 3f69e2d18..d7bcf682e 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(/\(+\d+\)$/).test(segment) + return RegExp(/\('+[\s\S]+'\)$/).test(segment) } /** From 0c4081eb8c2f3d4cec281c11986028a5d9e5fe61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enik=C5=91=20Pusztai?= Date: Fri, 25 Sep 2020 17:09:03 +0200 Subject: [PATCH 3/4] fix isItemSegment part2 --- 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 d7bcf682e..a8f11ba5a 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -44,11 +44,11 @@ export class PathHelper { } /** - * Checks if a specific segment is an Item segment or not (like "('Content1')"" or "(654)") + * Checks if a specific segment is an Item segment or not (like "('Content1')" or "Test(1)") * @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) || RegExp(/\(+\w+\d+\)$/).test(segment) } /** From 498d02cae15e4ba4a04825044c5f33f159464d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enik=C5=91=20Pusztai?= Date: Mon, 5 Oct 2020 17:05:04 +0200 Subject: [PATCH 4/4] change the result of content(12) path --- packages/sn-client-utils/src/path-helper.ts | 2 +- packages/sn-client-utils/test/path-helper.test.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/sn-client-utils/src/path-helper.ts b/packages/sn-client-utils/src/path-helper.ts index a8f11ba5a..f0a8c4c4a 100644 --- a/packages/sn-client-utils/src/path-helper.ts +++ b/packages/sn-client-utils/src/path-helper.ts @@ -24,7 +24,7 @@ export class PathHelper { * @param path The path to be splitted */ public static getSegments(path: string) { - if (!path) { + if (!path || path.startsWith('content') || path.startsWith('/content')) { return [] } // Split path at / and remove empty strings diff --git a/packages/sn-client-utils/test/path-helper.test.ts b/packages/sn-client-utils/test/path-helper.test.ts index 684fb541a..ee9a5f50b 100644 --- a/packages/sn-client-utils/test/path-helper.test.ts +++ b/packages/sn-client-utils/test/path-helper.test.ts @@ -179,7 +179,7 @@ export const pathHelperTests = describe('PathHelper', () => { expect(PathHelper.getSegments('/Root/Example/100pages(3).pdf')).toEqual(['Root', 'Example', '100pages(3).pdf']) }) it('Should split the path to segments', () => { - expect(PathHelper.getSegments('/content(123)')).toEqual(['content(123)']) + expect(PathHelper.getSegments('/content(123)')).toEqual([]) }) it('should throw an error if the path is /', () => { expect(() => PathHelper.getSegments('/')).toThrow() @@ -205,5 +205,13 @@ export const pathHelperTests = describe('PathHelper', () => { it('Should return the path in case of 1 segments', () => { expect(PathHelper.getParentPath('Root')).toBe('Root') }) + + it('Should return the path in case of 1 segments', () => { + expect(PathHelper.getParentPath('content(123)')).toBe('') + }) + + it('Should return the path in case of 1 segments', () => { + expect(PathHelper.getParentPath('/content(123)')).toBe('') + }) }) })