Interpolate typed-nil json.RawMessage as NULL#1782
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
Walkthrough
ChangesJSON interpolation fix
Author record update
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When interpolateParams=true, a typed-nil json.RawMessage (e.g. a nil
json.RawMessage stored in an interface) was interpolated as an empty
quoted string ('') instead of NULL. Inserting it into a JSON column made
the server reject it with Error 3140 (invalid JSON text).
The json.RawMessage case in interpolateParams lacked the nil guard that
the adjacent []byte case already has. Add the same guard so a nil value
is emitted as NULL, matching the server-side prepared statement path
(interpolateParams=false).
Fixes go-sql-driver#1781
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
05c8065 to
f179909
Compare
Description
Fixes #1781.
When
interpolateParams=true, a typed-niljson.RawMessage(for example a niljson.RawMessagecarried inside adriver.Value/interface{}) was interpolated as an empty quoted string ('') instead ofNULL. Inserting that into a JSON column made the server reject it withError 3140(invalid JSON text value).The typed nil passes the initial untyped-
nilcheck and reaches thecase json.RawMessage:branch ininterpolateParams(connection.go), which escaped/quoted the value unconditionally. The adjacentcase []byte:branch already guards forniland emitsNULL; this change adds the same guard sojson.RawMessage(nil)is interpolated asNULL, matching the server-side prepared-statement path (interpolateParams=false).Checklist
TestInterpolateParamsJSONRawMessageNil)