Skip to content

fix(generator): escape control characters in generated string literals - #164

Merged
leoafarias merged 1 commit into
release/1.7from
codex/ack-v2-generator-literals
Sep 29, 2026
Merged

leoafarias merged 1 commit into
release/1.7from
codex/ack-v2-generator-literals

Conversation

@leoafarias

@leoafarias leoafarias commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The generator had four copies of its string-literal helper (shared inference, schema-first emitter, class-first emitter, class-first graph builder). They escaped quotes, backslashes, and $, but wrote raw line terminators into single-quoted Dart source. A @Pattern, discriminator, or key value containing a newline or carriage return therefore generated invalid code. Other control characters were legal but unreadable.

  • Replace the four copies with one dartStringLiteral helper that also writes C0 control characters and U+2028/U+2029 as \uXXXX. DEL (0x7F) is legal in Dart strings and stays raw.
  • string_literal_test.dart round-trips several values through the Dart parser and checks that line terminators are escaped.
  • inference_literal_test.dart exercises the public shared-inference interface with four cases. The LF/CRLF case fails without the fix; the others lock in existing escaping and the new \uXXXX output.

Scope change

This fix now ships in Ack 1.7. The branch is one commit on the 1.7 stack (base: #174) instead of the older main snapshot, and it covers every generator literal, not only shared inference. The test file uses formatter output, which fixes the earlier CI formatting failure. The changelog entry is in the 1.7.0-beta.1 section; published history is untouched.

It stays independent of #163, which remains 2.0. Unpaired UTF-16 surrogates in annotation values are not handled; that is a possible follow-up.

Validation

Validated locally on the combined 1.7 tree (feat/ackmodel-class-description, head 2d632300), which includes every PR in the stack:

  • dart run melos run test --no-select passed. Strict analysis (--fatal-infos) found no issues in all seven packages. Tests passed: ack 1,311, ack_generator 347, ack_firebase_ai 98, ack_mcp_dart 63, ack_json_schema_builder 51, ack_annotations 8, plus the root and example suites.
  • A clean regeneration (delete *.ack.dart/*.g.dart, then melos run build) reproduced the committed output exactly.
  • dart scripts/api_check.dart 1.6.2 reported no breaking changes in any of the six packages. It cannot inspect generated consumer code, so it does not flag the typed copyWith getter; the ack_generator changelog documents that under Breaking.
  • dart scripts/publish_dry_run.dart reported 0 warnings for all six packages. verify_release_tag v1.7.0-beta.1 --skip-ancestry, dart format --set-exit-if-changed, and git diff --check passed.
  • No feat(ack): support Draft 2020-12 runtime import and export #171 or feat(generator): generate models from Draft 2020-12 schemas #167 commit is an ancestor of the stack.
  • Each PR was reviewed by an Opus 5.5 agent (AI-slop review, adversarial change review, and a description check). The blocking findings (constrained Set codegen in chore(release): prepare Ack 1.7.0-beta.2 #168, schema import prefix in feat(generator): add a static schema shorthand to AckInfer models #174) and the non-blocking fixes are included.

@leoafarias
leoafarias force-pushed the codex/ack-v2-generator-literals branch from 4440287 to d241b4c Compare September 29, 2026 14:09
@leoafarias leoafarias changed the title fix(generator): escape inferred string literals — 2.0 foundation fix(generator): escape control characters in inferred string literals Sep 29, 2026
@leoafarias
leoafarias changed the base branch from main to feat/short-model-schema-accessor September 29, 2026 14:10
@leoafarias
leoafarias added this pull request to stack #178 September 29, 2026 14:11
@leoafarias
leoafarias force-pushed the codex/ack-v2-generator-literals branch from d241b4c to 9d3b2df Compare September 29, 2026 14:21
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from 53e8d0f to 15974c5 Compare September 29, 2026 14:21
@leoafarias
leoafarias force-pushed the codex/ack-v2-generator-literals branch from 9d3b2df to f552a36 Compare September 29, 2026 14:55
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from 15974c5 to 6a1337d Compare September 29, 2026 14:55
@leoafarias leoafarias changed the title fix(generator): escape control characters in inferred string literals fix(generator): escape control characters in generated string literals Sep 29, 2026
@leoafarias
leoafarias marked this pull request as ready for review September 29, 2026 15:08
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from 6a1337d to dc85ba8 Compare September 29, 2026 15:43
@leoafarias
leoafarias force-pushed the codex/ack-v2-generator-literals branch from f552a36 to e35891d Compare September 29, 2026 15:43
The generator had four copies of its string-literal helper. They escaped
quotes, backslashes, and `$` but wrote real newlines into single-quoted
Dart source, so a @pattern, discriminator, or key value with a line
terminator generated invalid code. Share one dartStringLiteral helper
that also writes C0 controls and U+2028/U+2029 as \uXXXX.

Rebuilt from #164 (c9adbcd..4440287) on the 1.7 release baseline.
@leoafarias
leoafarias removed this pull request from stack #178 September 29, 2026 16:53
leoafarias added a commit that referenced this pull request Sep 29, 2026
Align the six publishable packages at 1.7.0-beta.1 and move unreleased
notes into the 1.7.0-beta.1 changelog sections. The release includes
shared inference, model adapter schemas, CodecSchema.canEncode, typed
copyWith, stricter constrained-Set validation, the @AckInfer schema
shorthand (#174), generated string-literal escaping (#164), and explicit
schema descriptions (#176). Update PUBLISHING.md for this candidate.

The Draft 2020-12 runtime (#171), JSON Schema-to-Dart generation (#167),
and the decoder error contract (#163) are deferred to 2.0.
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from dc85ba8 to edbedc2 Compare September 29, 2026 16:53
@leoafarias
leoafarias force-pushed the codex/ack-v2-generator-literals branch from e35891d to ab642a9 Compare September 29, 2026 16:53
Base automatically changed from feat/short-model-schema-accessor to release/1.7 September 29, 2026 16:53
@leoafarias
leoafarias merged commit ab642a9 into release/1.7 Sep 29, 2026
@leoafarias
leoafarias deleted the codex/ack-v2-generator-literals branch September 29, 2026 16:53
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