feat: add JSON parsing support while keeping regex {field:value} #21
Merged
hsluoyz merged 1 commit intoapache:masterfrom Sep 7, 2025
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: apache/casbin#1536
Issue Example:
In the example from the issue:
alice,data,read,1(where1is an integer)."alice", "data", "read", "1".r.exp == "1"(where"1"is a string).Ideally, the integer
1and the string"1"should not match. However, the Go version returnstrue. Upon investigation, it was found that the issue is not with the editor, Casdoor, Casbin engine, or the govaluate parser, but rather with the Go CLI’s handling.Root Cause:
Rust Version:
The Rust CLI uses
serde_json::Value::from_str()to parse the parameters. When1is input, it is parsed as a JSON number1. In the matcher comparison, the number1and the string"1"are compared, which results in1 != "1", returningfalse. This behavior is correct.Go Version (Before Modification):
The Go CLI only uses regular expressions to handle
{field: value}and treats all parameters as strings. Therefore, the input1is treated as the string"1". In the matcher,"1" == "1"matches successfully, but this is not what the user intended.Solution:
To address this, JSON parsing should be added as the primary method (mimicking Rust's
serde_json::Value::from_str), while retaining the existing regular expression{field: value}pattern support to maintain backward compatibility.