Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect hook transforms array results incorrectly. #2053

Closed
sechel opened this issue Sep 3, 2020 · 1 comment · Fixed by #2085
Closed

Protect hook transforms array results incorrectly. #2053

sechel opened this issue Sep 3, 2020 · 1 comment · Fixed by #2085

Comments

@sechel
Copy link

sechel commented Sep 3, 2020

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.

@sechel
Copy link
Author

sechel commented Oct 9, 2020

Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants