Skip to content

feat: add JSON parsing support while keeping regex {field:value} #21

Merged
hsluoyz merged 1 commit intoapache:masterfrom
FAUST-BENCHOU:fix/diif-between-go-and-rust
Sep 7, 2025
Merged

feat: add JSON parsing support while keeping regex {field:value} #21
hsluoyz merged 1 commit intoapache:masterfrom
FAUST-BENCHOU:fix/diif-between-go-and-rust

Conversation

@FAUST-BENCHOU
Copy link
Contributor

@FAUST-BENCHOU FAUST-BENCHOU commented Sep 7, 2025

Fix: apache/casbin#1536

Issue Example:

In the example from the issue:

  • The editor inputs alice,data,read,1 (where 1 is an integer).
  • The request sent to Casdoor would be similar to "alice", "data", "read", "1".
  • Then, the corresponding CLI is called, and the matcher condition is: r.exp == "1" (where "1" is a string).

Ideally, the integer 1 and the string "1" should not match. However, the Go version returns true. 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. When 1 is input, it is parsed as a JSON number 1. In the matcher comparison, the number 1 and the string "1" are compared, which results in 1 != "1", returning false. 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 input 1 is 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.

@FAUST-BENCHOU FAUST-BENCHOU reopened this Sep 7, 2025
@hsluoyz hsluoyz merged commit bd1ccd6 into apache:master Sep 7, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] Why Golang and Rust have different result

2 participants