Skip to content

Comments

Fix interpreter escaping issue#655

Open
Ynewtime wants to merge 1 commit intoobsidianmd:mainfrom
Ynewtime:claude/fix-clipper-escaping-Sxiy4
Open

Fix interpreter escaping issue#655
Ynewtime wants to merge 1 commit intoobsidianmd:mainfrom
Ynewtime:claude/fix-clipper-escaping-Sxiy4

Conversation

@Ynewtime
Copy link

@Ynewtime Ynewtime commented Dec 15, 2025

Hi,

issue

when using interpreter to optimize markdown content, if \ backslash or characters to be escaped are present, the output from LLM is not correctly escaped. e.g.:

image

Input content from web page:

# bash
export no_proxy="$NO_PROXY"

# powershell
.\Export-WindowsCerts.ps1

Write-Host "`n Export successfully" -ForegroundColor Green

Output content from LLM:

```bash
export no_proxy=\\"$NO_PROXY\\"
```

```powershell
# powershell
.\\Export-WindowsCerts.ps1

Write-Host \\"`n Export successfully\\" -ForegroundColor Green
```

You can reproduce this with this page: https://telegra.ph/obsidian-clipper-interpret-issue-reproduction-12-15

with this template:

interpret-test-clipper.json

or simply use this prompt for the content:

{{"better formatting markdown content in GFM styles. FORMAT ONLY, DO NOT MODIFY CONTENT!!!"}}

Basically this issue is provider- and model- agnostic, I tested this with most of the popular models including:

  • google/gemini-2.5-flash-lite
  • deepseek/deepseek-v3.2
  • anthropic/claude-haiku-4.5
  • x-ai/grok-code-fast-1

(as per my test, google/gemini-2.5-flash-lite is the best model in this scenario, fast and good enough)

solution

I tried to fix this issue with Claude Opus 4.5, and it was fixed in just one shot—worked really well. I reviewed the code and verified it by building, installing it in my browser, and testing it on hundreds of web pages.

image

Hence this PR.

You can also try the built extention here:

obsidian-web-clipper-0.12.0-chrome.zip

The interpreter was incorrectly handling JSON responses from LLMs when
the content contained double quotes or backslashes. The issue was:

1. The code was calling sanitizeJsonString() before attempting JSON.parse(),
   which could corrupt already-valid JSON containing escaped characters

2. The post-processing only handled newline escapes (\n) but not
   over-escaped quotes (\") or backslashes (\\)

Changes:
- Try direct JSON.parse() first, only fall back to sanitization on failure
- Add unescapeContent() helper that properly handles over-escaped sequences
- Process responses to convert \\" to " and \\\\ to \ after parsing

This fixes the bug where content like 'export no_proxy="$NO_PROXY"' was
being incorrectly output as 'export no_proxy=\"$NO_PROXY\"'.
@Ynewtime Ynewtime marked this pull request as draft December 19, 2025 03:39
@Ynewtime Ynewtime force-pushed the claude/fix-clipper-escaping-Sxiy4 branch from 8aafa91 to 96b893d Compare December 19, 2025 04:08
@Ynewtime Ynewtime marked this pull request as ready for review December 19, 2025 04:09
@Ynewtime Ynewtime force-pushed the claude/fix-clipper-escaping-Sxiy4 branch from 111b0ac to 96b893d Compare December 19, 2025 04:15
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