Skip to content

Commit

Permalink
fix broken action on content name w parenthesis (#1395)
Browse files Browse the repository at this point in the history
* fix broken action on content name w parenthesis

* remove unnecessary regex - nums not itemsegments

* normalize getsegment rx with itemsegment rx
remove faulty test logics

* mod path helper segment regex
  • Loading branch information
VargaJoe authored Jun 10, 2022
1 parent 2332398 commit 406523f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/sn-client-utils/src/path-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ 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')
const matches = lastItem.match(/(\('\w+'\)$)/g)
// Match if last item is Root/Example('content')
const matches = lastItem.match(/(\('.+'\)$)/g)
if (!matches) {
return [...splitted, lastItem]
}
Expand All @@ -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(/\('.+'\)$/).test(segment)
}

/**
Expand Down
13 changes: 4 additions & 9 deletions packages/sn-client-utils/test/path-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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')
})
Expand Down

0 comments on commit 406523f

Please sign in to comment.