8000 Protect hook transforms array results incorrectly. · Issue #2053 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content

Protect hook transforms array results incorrectly. #2053

@sechel

Description

@sechel

Steps to reproduce

Create a custom service and return an array of arrays, from the find method:

async find(params?: Params): Promise<number[][]> {
   return [
    [ 1, 2, 3, 4 ]
   ];
}

Add a protect hook from the @feathersjs/authentication-local package as after-hook to the global app hooks. Protect any field.

  after: {
    all: [
      protect('field')
    ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }

The result will be

[
 { 0: 1, 1: 2, 2: 3, 3: 4 } 
]

The source of this problem lies in these lines of the protect hook:

const o = (current: any) => {
const data = typeof current.toJSON === 'function'
? current.toJSON() : current;
return omit(data, fields);
};

Here you invoke _.omit on an array which leads to this result.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0