Skip to content

Unescape plain-text fields before persisting to SQLite#1370

Merged
SorraTheOrc merged 2 commits intomainfrom
copilot/unescape-strings-before-inserting-db
Apr 3, 2026
Merged

Unescape plain-text fields before persisting to SQLite#1370
SorraTheOrc merged 2 commits intomainfrom
copilot/unescape-strings-before-inserting-db

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Backslash escape artifacts (e.g. literal \n from CLI argument passing) were being stored verbatim in the DB instead of as their intended characters, reducing readability and requiring downstream post-processing.

Changes

  • unescapeText(s) — new exported function in persistent-store.ts; single-pass regex lookup converts \n, \t, \r, \\ to actual characters; all other sequences (unrecognised escapes, quotes, backticks) pass through unchanged

  • saveWorkItem() — applies unescapeText to title, description, deleteReason, and audit.text (inside the audit object, before JSON.stringify); structured fields (tags JSON, full audit envelope) are intentionally untouched

  • saveComment() — applies unescapeText to comment.comment

// input arrives as: "Line\\nBreak"
// stored in DB as:  "Line\nBreak"  (real newline)
unescapeText('Line\\nBreak') // → 'Line\nBreak'

// double-backslash is handled correctly in one pass
unescapeText('path\\\\file') // → 'path\file'
unescapeText('\\\\n')        // → '\n'  (backslash + n, not a newline)

Tests

  • 11 unit tests for unescapeText covering each sequence, multi-sequence strings, double-decode safety, and preservation of quotes/backticks/unknown escapes
  • 5 DB round-trip integration tests: description, title, comment body, audit.text (verifying JSON structure intact), and tags (verifying JSON field is not mutated)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh gh issue create --repo TheWizardsCode/ContextHub --title Sample --body-file - (http block)
    • Triggering command: /usr/bin/gh gh issue create --repo TheWizardsCode/ContextHub --title Sample --body-file - /tmp/wl-wt-subse/home/REDACTED/work/ContextHub/ContextHub/tests/cli/mock-bin/git k/ContextHub/Con-C bash text�� commit epo/.worklog/tmpsync 2 rgo/bin/bash init g/data sh bash (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 3, 2026 that may be closed by this pull request
Add unescapeText() to the persistence layer and apply it to plain-text
fields (title, description, deleteReason, comment body, and audit.text)
in saveWorkItem() and saveComment(). This converts backslash escape
artifacts (e.g. literal \n from CLI argument passing) to their intended
characters before storage.

JSON/structured fields (tags, refs, full audit JSON) are intentionally
excluded. Add 16 new tests: 11 unit tests for unescapeText and 5 DB
round-trip integration tests verifying the unescaping behaviour.

Agent-Logs-Url: https://github.com/TheWizardsCode/ContextHub/sessions/da790f96-11d5-483d-bc0d-40dcdfea3ed7

Co-authored-by: SorraTheOrc <250240+SorraTheOrc@users.noreply.github.com>
Copilot AI changed the title [WIP] Unescape strings before inserting into DB Unescape plain-text fields before persisting to SQLite Apr 3, 2026
Copilot AI requested a review from SorraTheOrc April 3, 2026 21:52
@SorraTheOrc SorraTheOrc marked this pull request as ready for review April 3, 2026 22:06
@SorraTheOrc SorraTheOrc merged commit 99a8eaa into main Apr 3, 2026
4 checks passed
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.

Unescape stings before inserting into DB.

2 participants