Skip to content

Normalize removing negated items with same start #7

@RyanTheAllmighty

Description

@RyanTheAllmighty

So I've been using accesscontrol to do filtering of objects based on roles and what attributes they have access to and I came across an issue that seems to track down to the normalize function of notation.

Given I have the following:

// allow access to all except password and password_reset_code
const globs = [
    '*',
    '!password',
    '!password_reset_code'
];

// normalize them (called as part of filter but the issue remains in normalize)
const normalizedGlobs = normalize(globs);

// prints out ['*', '!password']
console.log(normalizedGlobs);

It seems normalize is stripping out all negated globs that start with another negated attirbute.

It seems to be caused by https://github.com/onury/notation/blob/master/src/core/notation.glob.js#L383 as it does a regex check, in my case, like below:

/^password/.test('password_reset_code')

So any globs with the same beginning as a previous glob will be 'normalized' out.

Is this intended?

I've tried changing the ordering of the globs in the array and nothing seems to help short of changing the way I structure my data to ensure there is no repeated names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugTo be fixed.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions