-
Notifications
You must be signed in to change notification settings - Fork 309
Description
Description
The Issue
When using NosqlClient#updateRow in the TypeScript SDK to insert data containing multi-byte characters (such as Japanese), the data is stored in a corrupted state in the OCI NoSQL Database.
Root Cause
In NosqlClient#updateRow, the bodyContent is serialized using the default common.ObjectSerializer. This results in a JSON string containing raw multi-byte characters. When this string is passed to the underlying HTTP layer, it appears that the Content-Length is calculated based on character count rather than byte length, or the encoding is not handled as UTF-8, leading to data corruption at the API endpoint.
Comparison with Python SDK: The OCI Python SDK handles this correctly because its call_api implementation uses json.dumps(), which by default escapes non-ASCII characters into \uXXXX sequences, ensuring a safe ASCII-only payload.
Steps to Reproduce
Use NosqlClient#updateRow with a payload containing Japanese characters: {"name": "日本語"}.
Check the data in the OCI NoSQL Console.
The string appears as corrupted or broken characters.
Suggested Fix
The issue can be resolved by ensuring the JSON payload is ASCII-safe (Unicode escaped) before transmission, mimicking the behavior of the Python SDK.
- Add a helper method for Unicode escaping:
JavaScript
/*
* JSON UTF8 escape (Python-like json.dumps)
*/
jsonDumps(obj) {
return JSON.stringify(obj).replace(/[^\x00-\x7f]/g, (char) => {
return "\\u" + ("000" + char.charCodeAt(0).toString(16)).slice(-4);
});
}
- Modify updateRow in oci-nosql/lib/client.js (around line 1871):
Update the bodyContent assignment within oci_common_1.composeRequest:
- [ Before]
JavaScript
bodyContent: common.ObjectSerializer.serialize(updateRowRequest.updateRowDetails, "UpdateRowDetails", model.UpdateRowDetails.getJsonObj),
- [ After]
JavaScript
bodyContent: this.jsonDumps(updateRowRequest.updateRowDetails),
Environment Information
SDK Version: oci-sdk@2.121.1