zjncs opened a new pull request, #1755:
URL: https://github.com/apache/casbin/pull/1755

   ## Description
   
   `stringadapter.Adapter.LoadPolicy` discards the error returned by 
`persist.LoadPolicyLine`:
   
   ```go
   for _, str := range strs {
       if str == "" {
           continue
       }
       _ = persist.LoadPolicyLine(str, model)
   }
   ```
   
   A malformed line (e.g. an unterminated quoted field: `p, alice, data1, 
"read`) is therefore silently skipped: `LoadPolicy` returns `nil`, the model 
simply lacks the rule, and `Enforce` returns `false` with no error — the caller 
has no way to notice the typo'd policy.
   
   The file adapter propagates the same error 
(`persist/file-adapter/adapter.go` `loadPolicyFile` returns `handler(line, 
model)` errors), and `LoadPolicyLine`/`LoadPolicyArray` return errors precisely 
so callers can report malformed policies (see also #1106). This PR aligns the 
string adapter with that contract by returning the error.
   
   ## Testing
   
   - Added `Test_LoadPolicyMalformedLine` in 
`persist/string-adapter/adapter_test.go`: an adapter line with an unterminated 
quoted field must make `LoadPolicy` return an error.
     - Before the fix: FAIL — `LoadPolicy() error = nil, want a parse error for 
the unterminated quoted field`
     - After the fix: PASS
   - All existing tests in the package (`Test_KeyMatchRbac`, 
`Test_SavePolicyRoundTripWithCommas`, `Test_StringRbac`) still pass, and the 
full `go test ./...` suite passes (8 packages, no failures).
   - `go vet ./persist/string-adapter/` clean.
   
   Behavior change is limited to inputs that previously produced a 
silently-wrong model; well-formed input loads exactly as before.
   
   ---
   
   *This PR was prepared with AI assistance (GitHub Copilot / ZCode autonomous 
agent). All findings were verified manually against the codebase before 
submission.*
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to