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

Bug: json-bigint-patch causes CASL ability.can() to fail with BigInt conditions #1016

Open
guyhirsch opened this issue Jan 15, 2025 · 1 comment
Labels

Comments

@guyhirsch
Copy link

Describe the bug
When importing json-bigint-patch, the ability check in CASL fails to correctly match conditions using BigInt. Specifically, ability.can() incorrectly returns false when it should return true.

To Reproduce
Steps to reproduce the behavior:

  1. Ability configuration:
import 'json-bigint-patch';
import { createMongoAbility, subject } from '@casl/ability';

class Article {
  id: bigint;
}

type Actions = 'all';
type Subjects = Article | typeof Article | 'Article';

const ability = createMongoAbility<[Actions, Subjects]>([
  {
    action: 'all',
    subject: 'Article',
    conditions: { id: 5n },
  },
  {
    action: 'all',
    subject: 'Article',
    conditions: { id: 1n },
  },
]);

const article = new Article();
article.id = 1n;

console.log(ability.can('all', subject('Article', article))); // returns false, but it should return true
  1. How abilities are checked:
    Using ability.can() with a condition that should match, but it fails when json-bigint-patch is imported.

Expected behavior
When json-bigint-patch is imported, ability.can() should return true for matching conditions, just as it does without the import.

CASL Version

@casl/ability - v6.7.3

Environment:

  1. Node.js: v22.12.0
  2. TypeScript: v5.7.2
  3. json-bigint-patch: v0.0.8
@guyhirsch guyhirsch added the bug label Jan 15, 2025
@stalniy
Copy link
Owner

stalniy commented Jan 15, 2025

json-bigint-patch adds custom toJSON method. Ucsst expects toJSON to return primitive value, but in that patch lib it returns non primitive. I think it actually returns BigInt objectified instance. I’ll double check tomorrow

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

No branches or pull requests

2 participants