Skip to content

Commit ba7b052

Browse files
committed
fix: use line-ending backslash instead of newline for TOML closing delimiters
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.
1 parent e288495 commit ba7b052

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/specify_cli/integrations/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,11 @@ def _render_toml_string(value: str) -> str:
597597

598598
escaped = value.replace("\\", "\\\\")
599599
if '"""' not in escaped:
600-
sep = "\n" if escaped.endswith('"') else ""
601-
return '"""\n' + escaped + sep + '"""'
602-
if "'''" not in value:
603-
sep = "\n" if value.endswith("'") else ""
604-
return "'''\n" + value + sep + "'''"
600+
if escaped.endswith('"'):
601+
return '"""\n' + escaped + '\\\n"""'
602+
return '"""\n' + escaped + '"""'
603+
if "'''" not in value and not value.endswith("'"):
604+
return "'''\n" + value + "'''"
605605

606606
return '"' + (
607607
value.replace("\\", "\\\\")

tests/integrations/test_integration_base_toml.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_toml_prompt_excludes_frontmatter(self, tmp_path, monkeypatch):
205205
assert "---" not in parsed["prompt"]
206206

207207
def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):
208-
"""Body ending with `"` must not produce `""""` (#2113)."""
208+
"""Multiline body ending with `"` must not produce `""""` (#2113)."""
209209
i = get_integration(self.KEY)
210210
template = tmp_path / "sample.md"
211211
template.write_text(
@@ -214,7 +214,8 @@ def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):
214214
"scripts:\n"
215215
" sh: echo ok\n"
216216
"---\n"
217-
'Is "X clearly specified?"\n',
217+
"Check the following:\n"
218+
'- Correct: "Is X clearly specified?"\n',
218219
encoding="utf-8",
219220
)
220221
monkeypatch.setattr(i, "list_command_templates", lambda: [template])
@@ -226,8 +227,10 @@ def test_toml_no_ambiguous_closing_quotes(self, tmp_path, monkeypatch):
226227

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

232235
def test_toml_closing_delimiter_inline_when_safe(self, tmp_path, monkeypatch):
233236
"""Body NOT ending with `"` keeps closing `\"\"\"` inline (no extra newline)."""

0 commit comments

Comments
 (0)