Skip to content

Fix silent message corruption from absent/blank channel scripts (#344)#351

Open
e210 wants to merge 2 commits into
OpenIntegrationEngine:mainfrom
e210:fix/issue-344-undefined-preprocessor
Open

Fix silent message corruption from absent/blank channel scripts (#344)#351
e210 wants to merge 2 commits into
OpenIntegrationEngine:mainfrom
e210:fix/issue-344-undefined-preprocessor

Conversation

@e210

@e210 e210 commented Jul 16, 2026

Copy link
Copy Markdown

Fixes the root cause behind #344: POST /api/channels accepts a channel without <preprocessingScript>; the channel deploys "healthy" but corrupts every message to the literal string undefined on the wire.

Root cause

Two independent defects in JavaScriptUtil (full analysis in #344):

  1. JavaScriptBuilder.generateScript string-concatenates a null script into the JS wrapper, producing function doScript() { null }. compileAndAddScript caches it as a "custom" preprocessor because its body differs from the default script.
  2. executePreprocessorScripts guards results with result != null, but Rhino's Undefined is not Java nullContext.jsToJava coerces it to the string "undefined", which becomes the processed raw and flows to every destination.

Changes

  • compileAndAddScript: a null/blank script is now treated as absent — evict from the compiled-script cache and return false (all callers already handle false as "no script").
  • executePreprocessorScripts: both result checks (global + channel) now ignore Undefined, the same idiom getPostprocessorResponse already uses.
  • New JavaScriptUtilTest: 5 tests exercising the real Rhino path (TDD — each fix developed against a failing test).

Behavior change note

A user preprocessor with no return statement previously corrupted the message body to "undefined"; it now passes the message through unchanged. This is footgun-removal: returning the literal string "undefined" as content is never intentional (return ''; and return null; behave as before).

Verification

  • Full :server:test suite green.
  • E2E on the patched build (the issue's exact repro XML, MLLP sink logging raw bytes):
Channel variant Bytes on the wire (before) Bytes on the wire (after)
Issue's incomplete XML as-is \x0b undefined \x1c\r intact HL7 message

The broader ask in #344 — structural validation/normalization in POST /api/channels — is deliberately out of scope here; it deserves its own design discussion. This PR removes the data corruption.

@e210
e210 force-pushed the fix/issue-344-undefined-preprocessor branch from c0fd2d2 to 7642566 Compare July 16, 2026 07:48
@e210
e210 marked this pull request as ready for review July 16, 2026 07:50
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