nightshift/bug: editing titled snippets with colons corrupts data#11
Open
nightshift/bug: editing titled snippets with colons corrupts data#11
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
EditSnippetRow.saveChanges()inSources/EditSnippetRow.swiftcorrupts 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
Note: Important: some data(creates title="Note", value="Important: some data")"Note: Important: some data", which is correct"Note"and value is"Important: some data"— the round-trip was lossless here because the title didn't have": "Now the problematic case:
"Note: Important", value="data""Note: Important: data"SnippyParser.parse()splits at first": ", producing title="Note", value="Important: data""Note: Important"to"Note"Fix
EditSnippetRownow tracks whether the snippet originally had a title (originalTitleLength). When it did,saveChanges()splits at the last": "instead of re-parsing throughSnippyParser, 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,
SnippyParseris still used (first": "split), matching the behavior ofAddSnippetRow.