Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: use line-ending backslash instead of newline for TOML closing de…
…limiters

Address PR review feedback:
- Replace sep=newline with TOML line-ending backslash so the parsed
  value does not gain a trailing newline when body ends with a quote.
- For literal string (''') fallback, skip to escaped basic string when
  value ends with single quote instead of inserting a newline.
- Make test body multiline so it exercises the """ rendering path,
  and assert no trailing newline in parsed value.
  • Loading branch information
mnriem committed Apr 7, 2026
commit ba7b052d9b87ea14335e3e2d73119d36639b424e
10 changes: 5 additions & 5 deletions src/specify_cli/integrations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,11 @@ def _render_toml_string(value: str) -> str:

escaped = value.replace("\\", "\\\\")
if '"""' not in escaped:
sep = "\n" if escaped.endswith('"') else ""
return '"""\n' + escaped + sep + '"""'
if "'''" not in value:
sep = "\n" if value.endswith("'") else ""
return "'''\n" + value + sep + "'''"
if escaped.endswith('"'):
return '"""\n' + escaped + '\\\n"""'
return '"""\n' + escaped + '"""'
if "'''" not in value and not value.endswith("'"):
Comment thread
mnriem marked this conversation as resolved.
return "'''\n" + value + "'''"

return '"' + (
value.replace("\\", "\\\\")
Expand Down
7 changes: 5 additions & 2 deletions tests/integrations/test_integration_base_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_toml_prompt_excludes_frontmatter(self, tmp_path, monkeypatch):
assert "---" not in parsed["prompt"]

def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):
"""Body ending with `"` must not produce `""""` (#2113)."""
"""Multiline body ending with `"` must not produce `""""` (#2113)."""
i = get_integration(self.KEY)
template = tmp_path / "sample.md"
template.write_text(
Expand All @@ -214,7 +214,8 @@ def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):
"scripts:\n"
" sh: echo ok\n"
"---\n"
'Is "X clearly specified?"\n',
"Check the following:\n"
'- Correct: "Is X clearly specified?"\n',
encoding="utf-8",
)
monkeypatch.setattr(i, "list_command_templates", lambda: [template])
Expand All @@ -226,8 +227,10 @@ def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):

raw = cmd_files[0].read_text(encoding="utf-8")
assert '""""' not in raw, "closing delimiter must not merge with body quote"
assert '"""\n' in raw, "body must use multiline basic string"
parsed = tomllib.loads(raw)
assert parsed["prompt"].endswith('specified?"')
assert not parsed["prompt"].endswith("\n"), "parsed value must not gain a trailing newline"

Comment thread
mnriem marked this conversation as resolved.
def test_toml_closing_delimiter_inline_when_safe(self, tmp_path, monkeypatch):
"""Body NOT ending with `"` keeps closing `\"\"\"` inline (no extra newline)."""
Expand Down
Loading