-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zk graph --format json is not handling note titles with inner double quotes #389
Comments
@mcDevnagh @julio-lopez @jurica Would it be a case of manually sanitizing the note titles pre-json output? e.g, in the internal/core/note_format.go file? I had a look at the go It states something about a syntax like below being possible? Filename string `json:"filename,string"` Which should format it appropriately for wrapping in double quotes, but it didn't work on first try. |
We shouldn't have to sanitize. package main
import "encoding/json"
type Test struct {
Title string
}
func main() {
json, err := json.Marshal(Test{
Title: `"`,
})
if err != nil {
panic(err)
}
print(string(json))
} outputs {"Title":"\""} Is |
Ok great, thanks for this. As a heads up, I won't be able to look at this (or anything else) until March 17. I'll be on holiday 🏝️ |
note: narrowed this down a little bit and it actually looks like the culprit is When it's getting called in graph.go, line 70, something about the double quoted title is breaking it. This is why it spits out the entire shell env variables to Changing the file title from: |
It's actually due to the quotes not being escaped in link_format.go. These functions are used to render the links within documents as well. So escaping the double quotes here will render links within notes with the backslashes: |
Does that mean that the true culprit is links to titles with quotes and not titles with quotes themselves? |
In other words, quotes are being escaped properly everywhere in json output except the string for the filename's own link. If I hardcode the problem field output to {
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
"link": "foo",
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
} Otherwise it would in effect return this invalid json: {
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
+ "link": "[[another "test" note]]", <- the quotes around test are not escaped
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
} With the initial idea for the fix in #400 , the output looks like this: {
"filename": "another \"test\" note.md",
"filenameStem": "another \"test\" note",
"path": "another \"test\" note.md",
"absPath": "/Users/tjex/.local/src/zk-org/workbench/test-vault/another \"test\" note.md",
"title": "another \"test\" note",
"link": "[[another \"test\" note]]",
"lead": "",
"body": "",
"snippets": [],
"rawContent": "# another \"test\" note\n\n\n",
"wordCount": 4,
"tags": [],
"metadata": {},
"created": "2024-04-01T03:11:03.540446352Z",
"modified": "2024-04-01T03:11:05.217630323Z",
"checksum": "a121f8d06da1bff78c5e5eb4816d0417ab2ec22317bad43baedb51a20c60df68"
} Links are still rendered correctly within documents: # note title
[another "test" note](another%20%22test%22%20note)
[[another "test" note]] |
I have a lot of notes with titles that contain quotes and I have recently noticed this issue when I was trying to export notes in JSON format
I believe I have identified the source of this problem: #440. |
fixed with #440 |
Check if applicable
Describe the bug
I have four notes with inner double quotes in their titles, e.g.
This is a "note" title
.Running
zk graph --json > notes.json
dumps json fine except for these notes. In their place, is a singular comma:The weird thing is that there's only three instances of this, despite there being four notes with this quote pattern. Additionally, all four notes are not in the json file. In other words, three have been replaced with a singular column, and one has vanished altogether.
Additionally, it seems like notes with double quotes in their title create some strange behaviour.
it is exclusively those notes that are printed to stdout, and after the printing of each note's body, my zsh environment variables are printed as well. Which is super weird, and would freak me out if I didn't know that this project is a legitimate project run by honest people haha.
I'm sure that will be fixed, once the strings get handled, but just wanted to put it out there.
How to reproduce?
zk graph --json > notes.json
and check if it's already bug freeThis is a "test" note
zk index
zk graph --json > notes2.json
Theoretically, there should be a singular line with a comma
zk configuration
Environment
The text was updated successfully, but these errors were encountered: