Repository navigation
Fix #3987: Arabic / Hebrew records read as logical text, stored visual - #4256
Merged
Merged
Conversation
A 3270 had no BiDi engine, so the host kept right-to-left text in visual order (as the screen showed it): `שלום` is stored as the bytes of `םולש`. The entity codecs decoded it as-is, so a modern frontend -- which takes a String as logical -- rendered every Arabic / Hebrew field backwards. - CobolRecords.text() returns logical order and putText() stores visual order under a visual page; sortKey() orders by the visual bytes VSAM holds. The transform is java.text.Bidi (JDK, no dependency): RTL runs reversed, numbers kept left to right, brackets mirrored, shaped Arabic forms kept, so a record read and re-written is byte-exact. CobolRecords.logical / visual are public for record bytes outside the codecs. - data.bidi_layout: auto | logical | visual_ltr | visual_rtl. visual_ltr is IBM's host default (the first byte at the screen's left); visual_rtl is a screen-reverse terminal (Arabic stored in reading order, numbers reversed). auto = visual_ltr under IBM420 / IBM424 / IBM864 / IBM862, else logical. - cp420 (EBCDIC Arabic) registered with codecs, from the JDK's IBM420 table: record_charset / code_page cp420 failed config validation before. cp420 and cp424 join EBCDIC_CODE_PAGES. - A porting rule on visual estates: keep Strings logical, never reverse by hand, flag reference modification / INSPECT of such a field. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3987.
What was broken
A 3270 had no BiDi engine, so the host kept Arabic and Hebrew in visual order: the characters left to right as the screen showed them.
שלוםis stored as the bytes ofםולש.CobolRecords.text()decoded those bytes as they were. A browser treats every String as logical (reading order), so each right-to-left field came out backwards.Changes
CobolRecords.text()returns logical order andputText()stores visual order back when the page is visual.sortKey()encodes the visual bytes, so keys still sort the way VSAM sorts them.java.text.Bidifrom the JDK, so no new dependency. Right-to-left runs are reversed, numbers stay left to right, brackets are mirrored, and the shaped (presentation) forms of IBM420 are kept. A record that is read and written again is byte-exact.CobolRecords.logical(s)/visual(s)are public, for record bytes that don't go through the codecs (COMMAREAs, hand-built records).data.bidi_layout:auto | logical | visual_ltr | visual_rtl.visual_ltr: the record's first byte is the screen's leftmost character, IBM's host default.visual_rtl: a screen-reverse terminal. Arabic is stored in reading order and numbers and Latin are reversed.automeansvisual_ltrunder IBM420 / IBM424 (EBCDIC Arabic / Hebrew) and IBM864 / IBM862 (PC Arabic / Hebrew), andlogicaleverywhere else. Windows-1255/1256 and ISO-8859-6/8 are logical by default. A barevisualvalue is rejected, because it doesn't say which side of the screen the first byte is on.codecs. Python ships cp424 but not cp420, sorecord_charset: cp420/code_page: cp420used to fail config validation. The table is the JDK IBM420 diff against cp037, built the same way as the national pages; bytes the JDK leaves unmapped stay undefined. cp420 and cp424 joinEBCDIC_CODE_PAGES.bidi_rules), added only on visual estates: keep Strings logical, never reverse one by hand, convert at a raw-bytes boundary withlogical/visual, and flag a reference modification or INSPECT of such a field in a TODO.dead_key_audit.py: allowlistbidi_layoutandrecord_charset. Both areDatafields thattarget_as_dictwrites withvars().Limits
125 ديصرcan be125 رصيدorرصيد 125; both give the same screen and the same bytes. The reverse step uses the bidi algorithm in the screen's direction, which undoes itself for words and numbers. A fuzz run over realistic Arabic/Hebrew text with digits and punctuation found 47 of 200,000 strings that don't come back exactly. Every one is built around a cluster of punctuation sitting between a right-to-left letter and a digit. The Javadoc says so.det/cobolrt/Cobol.text) is not changed. Its program storage stays visual, as on the mainframe. The DTO boundary there is a follow-up.Verification
test_bidi_layout.py: a Java probe on IBM424 / IBM420 / IBM037 / windows-1255, compiled under each of the four layouts. It covers the read and the write, numbers inside an Arabic run, mirrored brackets, byte-exact round trips (shaped forms included), Latin unchanged,sortKeyon visual bytes, and the visual_rtl Hebrew-plus-number case. It also checks config validation, which estates get the rule, the cp420 codec, and that the Java page set matchesjava_target.VISUAL_BIDI_PAGES. I ran it locally with JDK 21's compiler module; it skips withoutjavac.tests/cobol_mainframe,tests/cics_crucible, codec tests: pass. The first run caught a raw«»in the template;test_generated_java_is_asciipasses after escaping it.🤖 Generated with Claude Code