Skip to content

fix(codegen): embed user strings into generated ObjectScript correctly - #93

Open
PYDuquesnoy wants to merge 1 commit into
intersystems-community:masterfrom
PYDuquesnoy:upstream-sync/fix-objectscript-escaping
Open

fix(codegen): embed user strings into generated ObjectScript correctly#93
PYDuquesnoy wants to merge 1 commit into
intersystems-community:masterfrom
PYDuquesnoy:upstream-sync/fix-objectscript-escaping

Conversation

@PYDuquesnoy

Copy link
Copy Markdown
Collaborator

Fixes #92

What

Every tool that generates ObjectScript embedded user-supplied strings into ObjectScript "..." literals with the wrong escaping for the context: SQL-style '' doubling, or C-style \\ / \". ObjectScript escapes a quote inside a literal by doubling it (""); backslash is an ordinary character. As a result:

  • iris_lookup_transfer action=import failed 100% with <SYNTAX>%Export XML always carries attribute quotes, and \" tears the literal open
  • values containing ' were silently written doubled (success:true): credential passwords (Ens.Config.Credentials.SetCredential), Security.Users passwords, lookup values, production item settings
  • values containing " or newlines crashed the generated routine

How

New module crates/iris-agentic-dev-core/src/objectscript.rs:

  • os_str_expr(s) — renders any string as a single-line ObjectScript expression: printable runs become quoted literals with " doubled, control characters are spliced via $CHAR(n,...) (a literal cannot span source lines, and the exec-class builder splits on \n)
  • os_stream_write_stmts(var, payload, chunk) — chunked Do var.Write(...) statements for long payloads (the import XML), so no generated line approaches the routine line-length limit

Converted every ObjectScript-context embed site:

  • tools/interop.rs — production item enable/disable/get_settings/set_settings, credential create/update/delete, lookup manage get/set/delete/list_keys, lookup transfer export/import (import now goes through build_lookup_import_code, unit-tested), autostart set
  • tools/admin.rs — user get-roles/create/modify/delete, security check, namespace create/delete, webapp get/create/delete
  • tools/dict.rsbuild_message_map_code class-name embed

SQL-context escapes (iris.query paths, coverage.rs, info.rs) are untouched — '' doubling is correct there.

The unit tests that asserted the wrong escaping (production_item_escape_in_objectscript_code, credential_*_escaping, xml_escaping_backslash_and_quote) now assert the correct behavior, plus new tests that feed real quote-heavy multi-line XML through the import code builder and check every generated line holds only balanced literals.

Testing

  • cargo build clean, cargo clippy --all-targets clean, cargo fmt applied
  • cargo test -p iris-agentic-dev-core --lib: 1002 passed, 0 failed
  • e2e test file compiles; the live lookup round-trip test now asserts real success (the old asserts accepted error_code as a pass, which is how the 7/7 import failures stayed green) and exercises a quote/apostrophe/accent value against a live IRIS

This is a port of intersystems-ib/iris-interop-dev#7 (where the bug was found and fixed against a 0.6.x base), re-applied onto current master.

🤖 Generated with Claude Code

Every tool that generated ObjectScript embedded user-supplied strings with
the wrong escaping for the context: SQL-style '' doubling (or C-style \")
inside ObjectScript "..." literals. ObjectScript escapes a quote inside a
literal by doubling it; backslash is an ordinary character. Consequences:

- iris_lookup_transfer import failed 100% with <SYNTAX> - XML always
  carries attribute quotes, and \" tears the literal open
- values containing ' were silently corrupted to '' on write: lookup
  values, credential passwords, Security.Users passwords, item settings
- values containing " or newlines crashed the generated routine

New module `objectscript` renders any string as a safe single-line
expression (quotes doubled, control chars via $CHAR, long payloads
chunked across Write statements), used by every ObjectScript-context
embed site in interop.rs, admin.rs and dict.rs. SQL-context escapes
are untouched.

Fixes intersystems-community#92

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant