Skip to content

Commit

Permalink
Merge pull request #716 from nextcloud-libraries/fix/fileid-negative
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv committed Aug 3, 2023
2 parents 1a5aa9b + d594137 commit 47e3436
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions __tests__/files/node.spec.ts
Expand Up @@ -52,6 +52,17 @@ describe('FileId attribute', () => {
expect(file.fileid).toBe(1234)
})

// Mostly used when a node is unavailable
test('FileId negative fallback', () => {
const file = new File({
source: 'https://cloud.domain.com/remote.php/dav/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
id: -1234,
})
expect(file.fileid).toBe(-1234)
})

test('FileId attributes fallback', () => {
const file = new Folder({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/',
Expand All @@ -73,13 +84,6 @@ describe('Sanity checks', () => {
owner: 'emma',
id: '1234' as unknown as number,
})).toThrowError('Invalid id type of value')

expect(() => new File({
source: 'https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg',
mime: 'image/jpeg',
owner: 'emma',
id: -1234,
})).toThrowError('Invalid id type of value')
})

test('Invalid source', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/files/nodeData.ts
Expand Up @@ -81,7 +81,7 @@ export const isDavRessource = function(source: string, davService: RegExp): bool
* @param davService Pattern to check if source is DAV ressource
*/
export const validateData = (data: NodeData, davService: RegExp) => {
if (data.id && (typeof data.id !== 'number' || data.id < 0)) {
if (data.id && typeof data.id !== 'number') {
throw new Error('Invalid id type of value')
}

Expand Down

0 comments on commit 47e3436

Please sign in to comment.