Skip to content

fix(ui): escape quotes/backslashes when promoting ini() comments to l… - #1198

Open
billdenney wants to merge 1 commit into
mainfrom
fix-ini-comment-label-quote-escaping
Open

fix(ui): escape quotes/backslashes when promoting ini() comments to l…#1198
billdenney wants to merge 1 commit into
mainfrom
fix-ini-comment-label-quote-escaping

Conversation

@billdenney

@billdenney billdenney commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

…abel()

A trailing # comment on an ini({}) line is promoted to a label() call by .rxReplaceCommentWithLabel() when the model is parsed with its source refs intact. The label text was escaped correctly by deparse1(), but was then interpolated into the replacement argument of sub(), which parses backslashes in a replacement and strips one level. That undid the escaping, so a comment containing a double quote generated label("fixed to a "small value""), which failed the re-parse with a bare syntax error pointing into regenerated text rather than at the offending source line. A lone backslash in the comment failed the same way.

Build the promoted line with paste0() instead, leaving deparse1()'s escaping intact. Output is byte-identical for every comment that already worked, including ones containing single quotes.

Because the promotion only runs when source refs are kept, the same model resolved fine without them -- so a package build could be green while a test suite run with keep.source = TRUE was red on the identical file.

Adds an enumerating test over plain, double-quoted, unbalanced-quote, single-quoted, backslash, escaped-quote and mixed comments asserting the comment text round-trips into the label verbatim, plus exact-output checks for a population parameter and an eta line, and a check that a line already carrying label() is left alone.

Fixes #1195

…abel()

A trailing `#` comment on an `ini({})` line is promoted to a `label()`
call by `.rxReplaceCommentWithLabel()` when the model is parsed with its
source refs intact.  The label text was escaped correctly by `deparse1()`,
but was then interpolated into the *replacement* argument of `sub()`,
which parses backslashes in a replacement and strips one level.  That
undid the escaping, so a comment containing a double quote generated
`label("fixed to a "small value"")`, which failed the re-parse with a bare
syntax error pointing into regenerated text rather than at the offending
source line.  A lone backslash in the comment failed the same way.

Build the promoted line with `paste0()` instead, leaving `deparse1()`'s
escaping intact.  Output is byte-identical for every comment that already
worked, including ones containing single quotes.

Because the promotion only runs when source refs are kept, the same model
resolved fine without them -- so a package build could be green while a
test suite run with `keep.source = TRUE` was red on the identical file.

Adds an enumerating test over plain, double-quoted, unbalanced-quote,
single-quoted, backslash, escaped-quote and mixed comments asserting the
comment text round-trips into the label verbatim, plus exact-output checks
for a population parameter and an eta line, and a check that a line
already carrying `label()` is left alone.

Fixes nlmixr2/rxode2 issue 1195

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@billdenney
billdenney marked this pull request as ready for review August 7, 2026 01:46
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.

ini() comment-to-label() promotion breaks on a " (or \) in the comment: sub() strips deparse1()'s escaping

1 participant