Skip to content

[ENG-3355]Fix placeholder consolidation reintroducing stray braces on shared boundary runs#4

Open
Deeshath wants to merge 5 commits into
masterfrom
bugfix/eng-3355-placeholder-consolidation
Open

[ENG-3355]Fix placeholder consolidation reintroducing stray braces on shared boundary runs#4
Deeshath wants to merge 5 commits into
masterfrom
bugfix/eng-3355-placeholder-consolidation

Conversation

@Deeshath

@Deeshath Deeshath commented Jul 2, 2026

Copy link
Copy Markdown

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_content corrupts 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.rb builds the exact shared-boundary structure and asserts:

  1. consolidation does not alter the visible text (fails on old code: {{offer.job_title}}}});
  2. after substitution there is no orphan brace (fails on old code: Senior Account Executive}}).
  • New spec: 2 examples. Full suite: 138 examples, 0 failures (136 + 2 new; no regressions).
  • Verified against the real customer template: Executive}}, 44,00,000}}, L5}} no longer appear; genuine unresolved placeholders ({{docusign.*}} etc.) left intact.

Note

Please cut a v1.0.4 tag on merge — Kula core pins this fork by tag and will bump to it.

@Deeshath Deeshath requested a review from sumankula July 3, 2026 16:50
@Deeshath Deeshath changed the title Fix placeholder consolidation reintroducing stray braces on shared boundary runs [ENG-3355]Fix placeholder consolidation reintroducing stray braces on shared boundary runs Jul 3, 2026
Deeshath added 2 commits July 7, 2026 18:00
…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.
@Deeshath Deeshath force-pushed the bugfix/eng-3355-placeholder-consolidation branch from 2abfeaf to 17b2c2e Compare July 13, 2026 14:43
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.

2 participants