Skip to content

[Bug]: Multi-byte characters (Japanese) are corrupted in NosqlClient#updateRow due to improper JSON serialization #830

@T-Nosaka

Description

@T-Nosaka

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.

  1. 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);
    });
}
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions