Skip to content

HTML-894: Fix documentToString() indentation corrupting lookup tags nested in script blocks - #350

Merged
mseaton merged 1 commit into
masterfrom
HTML-894
Sep 17, 2026
Merged

mseaton merged 1 commit into
masterfrom
HTML-894

Conversation

@mseaton

@mseaton mseaton commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

  • <lookup> (or other substitution) tags nested inside inline <script> blocks get whitespace/newlines injected around the substituted value when the form also contains <macros>, <page>, <translations>, or <subform>.
  • Root cause: those elements each trigger an internal String→DOM→String round-trip in HtmlFormEntryGenerator (via HtmlFormEntryUtil.documentToString()) before the <lookup> tag is actually substituted by applyTags(). documentToString() sets OutputKeys.INDENT="yes", and JAXP's indenting transformer inserts whitespace text nodes around element boundaries in mixed text/element content — corrupting a <lookup> sitting inside <script> text. A literal newline injected into a quoted JS string is invalid syntax, so the browser throws Uncaught SyntaxError: Invalid or unexpected token and the script fails to run.
  • Fix: add a documentToString(Document, boolean indent) overload, and pass indent=false at the 4 purely-internal round-trip call sites (applyMacros, processPages, applyTranslations, processSubforms) since that intermediate xml is only consumed by further string/regex processing, never shown to a human. InitializerExportUtil and OrderTagAttributeDescriptor keep indent=true, preserving human-readable exported form XML.

Test plan

  • mvn -pl api compile succeeds
  • mvn -pl api test passes (no regressions)
  • Manually verify against the original repro form (an ART Visit-style htmlform with <macros> and a <script> block containing <lookup expression="patient.uuid"/>) that the rendered script is no longer corrupted

🤖 Generated with Claude Code

…ested in script blocks

Forms containing a <script> block with a <lookup> (or other substitution)
tag, combined with <macros>, <page>, <translations>, or <subform>, get
whitespace/newlines injected around the substituted value because
HtmlFormEntryGenerator's internal DOM round-trips indent the serialized
xml, and JAXP's indenter inserts whitespace text nodes around element
boundaries in mixed text/element content. An injected literal newline
inside a quoted JS string is invalid syntax, breaking the form's script.

Add a documentToString(Document, boolean indent) overload and use
indent=false for the purely-internal round-trips in applyMacros,
processPages, applyTranslations, and processSubforms, since that
intermediate xml is never shown to a human. InitializerExportUtil and
OrderTagAttributeDescriptor keep indent=true, preserving human-readable
export output.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mseaton
mseaton merged commit 5b44713 into master Sep 17, 2026
5 checks passed
@mseaton
mseaton deleted the HTML-894 branch September 17, 2026 16:26
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