Skip to content

fix: separate Base64 text encoding from payload charset - #18

Open
Hanabi9248 wants to merge 1 commit into
IvorySQL:IVYC_REL_5_STABLEfrom
Hanabi9248:codex/base64-carrier-charset
Open

Hanabi9248 wants to merge 1 commit into
IvorySQL:IVYC_REL_5_STABLEfrom
Hanabi9248:codex/base64-carrier-charset

Conversation

@Hanabi9248

Copy link
Copy Markdown

The explicit charset in the string codecs is currently used for both the payload and the Base64 carrier text. With UTF-16 this turns encoded ASCII bytes into unrelated characters and introduces BOM/zero bytes when decoding canonical Base64 input; even an encode/decode round trip can fail.

Use US_ASCII for the Base64 text in the basic and URL-safe string codecs. Keep the caller-selected charset for original payload bytes and recovered text. For example, UTF-16 encoding of A must produce /v8AQQ== (basic) or _v8AQQ== (URL-safe), preserving the payload BOM. JsonBuilder and other helpers are unchanged.

Validation: compiled the complete production Base64Util plus six unchanged support classes against the real, already-installed Spring Core 5.2.10.RELEASE JAR, using JDK 25.0.4.101 with javac --release 8. The standalone regression uses JDK java.util.Base64 as an independent oracle. Baseline: 8 failures and 4 passing controls; candidate: all 12 cases pass. Both alphabets cover UTF-16 encoding, canonical decoding and round trips, UTF-16LE encoding, default UTF-8 Chinese text and explicit Latin-1 controls. Three obsolete Java 8 source/target warnings were emitted.

Example in Bash, from the repository root with SPRING_CORE_JAR pointing to an existing matching JAR:

mkdir -p "$TMPDIR/base64-classes"
javac --release 8 -encoding UTF-8 -cp "$SPRING_CORE_JAR" -d "$TMPDIR/base64-classes" common/src/main/java/com/highgo/cloud/util/toolkit/{Base64Util,StringUtil,ObjectUtil}.java common/src/main/java/com/highgo/cloud/util/toolkit/support/{Charsets,CharPool,RandomType,StringPool}.java tests/Base64CharsetRegression.java
java -cp "$TMPDIR/base64-classes:$SPRING_CORE_JAR" Base64CharsetRegression

Use a semicolon classpath separator on Windows. Java 8 runtime, Maven/Spring full-service tests, the whole repository and arbitrary charsets/invalid-input policies were not tested. This validates the public codec overloads, without claiming a specific application endpoint.

Assisted-by: OpenAI gpt-6.1-sol

Use ASCII for the Base64 carrier in basic and URL-safe string codecs.
Keep the requested charset for original and recovered payload bytes.
Add UTF-16 interoperability and round-trip regressions with UTF-8 and
Latin-1 controls against the complete production class.

Signed-off-by: Hanabi <317387557+Hanabi9248@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant