[ENG-3355]Fix placeholder consolidation reintroducing stray braces on shared boundary runs#4
Open
Deeshath wants to merge 5 commits into
Open
[ENG-3355]Fix placeholder consolidation reintroducing stray braces on shared boundary runs#4Deeshath wants to merge 5 commits into
Deeshath wants to merge 5 commits into
Conversation
sumankula
approved these changes
Jul 6, 2026
…olidation [ENG-3355]
Text#content= now re-asserts xml:space="preserve" when the written text has
leading/trailing whitespace. Consolidation/substitution can rewrite a run's
<w:t> to text beginning/ending with a space (e.g. " office." after a merged
{{offer.office}}), which Word/LibreOffice trim without the attribute — the
"Indiaoffice" collapse. Adds unit specs on Text#content= and an integration
spec on the shared-boundary consolidation case.
2abfeaf to
17b2c2e
Compare
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.
Problem
When Word splits placeholders across runs (proofing marks —
<w:proofErr>) and fuses one token's closing}}into the same run as the next token's opening{{— e.g. a run whose text is literally}} in Grade {{—validate_placeholder_contentcorrupts the paragraph.It builds the run/position map once, then edits runs in place per placeholder. When two placeholders share that boundary run, processing the second placeholder rewrites the shared run from the stale cached text, resurrecting the
}}the first placeholder's merge had already trimmed. The paragraph's visible text changes ({{a}}becomes{{a}}}}), and after substitution the value renders with a trailing}}(Senior Account Executive}}).Downstream (Kula ENG-3355): offer-letter merge fields rendered with a stray
}}after the value.Fix
Replace the in-place, static-map editing with a single position-ordered reconstruction pass: walk the joined text once, assign each placeholder wholly to the run holding its opening
{{, and assign every other character to its original run. Keeps each placeholder atomic even when tokens share a boundary run, and — unlike the old code — never changes the paragraph's overall visible text.Tests
spec/docx/paragraph_placeholder_spec.rbbuilds the exact shared-boundary structure and asserts:{{offer.job_title}}}});Senior Account Executive}}).Executive}},44,00,000}},L5}}no longer appear; genuine unresolved placeholders ({{docusign.*}}etc.) left intact.Note
Please cut a
v1.0.4tag on merge — Kula core pins this fork by tag and will bump to it.