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

Sort roles by position in permissions calculation #609

Merged
merged 2 commits into from
Mar 16, 2019
Merged

Sort roles by position in permissions calculation #609

merged 2 commits into from
Mar 16, 2019

Conversation

z64
Copy link
Collaborator

@z64 z64 commented Mar 16, 2019

The crux of this bug is based on the fact that the internal order of roles is undefined: they are in whatever order Discord sends them to us. This causes our reduce to be unstable based on this position, because of the following, where:

  • each element is a role
  • true represents permissions field being checked
  • pN is the roles position
[false, true, false].reduce { |a, e| e } # => false
 p1     p3^^  p2

[false, false, true].reduce { |a, e| e } # => true
 p1     p2     p3^^

Sorting during our reduction ensures a set permission by a higher role
is not masked by a lower one.

Fixes #607

The crux of this bug is based on the fact that the internal order of
roles is undefined: they are in whatever order Discord sends them to us.
This causes our reduce to be unstable based on this position, because of
the following, where:

- each element is a role
- "true" represents permissions field being checked
- pN is the roles position

    [false, true, false].reduce { |a, e| e } # => false
     p1     p3^^  p2
    [false, false, true].reduce { |a, e| e } # => true
     p1     p2     p3^^

Sorting during our reduction ensures a set permission by a higher role
is not masked by a lower one.
@z64 z64 merged commit 9caf6e4 into discordrb:master Mar 16, 2019
@z64 z64 deleted the issue-607 branch March 16, 2019 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant