You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@casbin.apache.org by "nikolauspschuetz (via GitHub)" <gi...@apache.org> on 2026/07/26 19:04:51 UTC
[PR] fix: preserve non-ASCII literals in EscapeStringLiterals [casbin]
nikolauspschuetz opened a new pull request, #1746:
URL: https://github.com/apache/casbin/pull/1746
### What
`EscapeStringLiterals` iterated the matcher expression **byte-by-byte** and re-encoded each byte as a rune:
```go
for i := 0; i < len(expr); i++ {
ch := rune(expr[i])
...
result.WriteRune(ch)
}
```
For any multi-byte UTF-8 character, every continuation byte (`0x80`–`0xFF`) was written out as its own code point, corrupting the literal:
```
EscapeStringLiterals(`r.sub == '香港'`) => `r.sub == 'é¦\x99港'` // 17 -> 23 bytes
```
This runs at model-load time (`model.go` `loadAssertion`) and inside `EnforceWithMatcher`, so a matcher containing a non-ASCII string literal silently stopped matching the real request value — i.e. **wrong allow/deny decisions** for any policy or matcher using non-ASCII literals.
### Fix
Iterate over runes (`for _, ch := range expr`) so multi-byte characters round-trip unchanged. The backslash-doubling and quote-tracking logic is unchanged. Added regression cases for CJK and accented literals to `TestEscapeStringLiterals`.
`go test ./util/ -run TestEscapeStringLiterals` fails before this change (the new cases) and passes after; the full `util` package tests pass, `go vet` and `gofmt` are clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org
Re: [PR] fix: preserve non-ASCII literals in EscapeStringLiterals [casbin]
Posted by "hsluoyz (via GitHub)" <gi...@apache.org>.
hsluoyz merged PR #1746:
URL: https://github.com/apache/casbin/pull/1746
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@casbin.apache.org
For additional commands, e-mail: commits-help@casbin.apache.org