Skip to content

nightshift/bug: editing titled snippets with colons corrupts data#11

Open
perandre wants to merge 1 commit intomainfrom
nightshift/bug-2026-04-13-edit-title-colon
Open

nightshift/bug: editing titled snippets with colons corrupts data#11
perandre wants to merge 1 commit intomainfrom
nightshift/bug-2026-04-13-edit-title-colon

Conversation

@perandre
Copy link
Copy Markdown
Owner

Bug

EditSnippetRow.saveChanges() in Sources/EditSnippetRow.swift corrupts snippet titles that contain ": ".

When editing a snippet with title "Note: Important" and value "some data", the edit field is pre-filled with "Note: Important: some data". On save, SnippyParser.parse() splits at the first ": ", producing title="Note" and value="Important: some data" — silently destroying the original title.

Repro

  1. Add a snippet by typing Note: Important: some data (creates title="Note", value="Important: some data")
  2. Edit the snippet — field shows "Note: Important: some data", which is correct
  3. Press Return without changing anything
  4. The title is now "Note" and value is "Important: some data" — the round-trip was lossless here because the title didn't have ": "

Now the problematic case:

  1. Programmatically or via JSON have a snippet with title="Note: Important", value="data"
  2. Edit it — field shows "Note: Important: data"
  3. Press Return — SnippyParser.parse() splits at first ": ", producing title="Note", value="Important: data"
  4. The title has been corrupted from "Note: Important" to "Note"

Fix

EditSnippetRow now tracks whether the snippet originally had a title (originalTitleLength). When it did, saveChanges() splits at the last ": " instead of re-parsing through SnippyParser, which always splits at the first. This preserves titles containing colons while keeping the single-field editing UX.

For snippets that originally had no title, SnippyParser is still used (first ": " split), matching the behavior of AddSnippetRow.

EditSnippetRow reconstructs the edit field as "title: value". When saved,
SnippyParser.parse() splits at the first ": ", which is wrong when the
title itself contains that sequence (e.g. "Note: Important").

The fix tracks whether the snippet originally had a title and, when it
did, splits at the *last* ": " on save instead of re-parsing through
SnippyParser. This preserves titles that contain colons while keeping
the single-field editing UX intact.
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.

2 participants