fix: works, but with caveat of old tests breaking.

It would seem that the old tesh test is not taking into account note
titles with `"` marks. Therefore, the failing test may be a sign of the
test needing to be updated, rather than this fix being void.
json-link-sanitize
tjex 2 months ago
parent 05c50a70d5
commit be46e734bf

@ -5,6 +5,7 @@ import (
"fmt"
"regexp"
"time"
"strings"
)
// NoteFormatter formats notes to be printed on the screen.
@ -32,6 +33,11 @@ func newNoteFormatter(basePath string, template Template, linkFormatter LinkForm
snippets = append(snippets, noteTermRegex.ReplaceAllString(snippet, termRepl))
}
//FIXME: if notes have `"` in their titles, they will break when
//executing `zk graph --format json` as `Link:...` gets unescaped quotes
//from `newLazyStringer`. Issue: https://github.com/zk-org/zk/issues/389
// escaping the quotes breaks tesh tests, but is the test perhaps
// guarding a less robust solution?
return template.Render(noteFormatRenderContext{
Filename: note.Filename(),
FilenameStem: note.FilenameStem(),
@ -44,6 +50,7 @@ func newNoteFormatter(basePath string, template Template, linkFormatter LinkForm
return ""
}
link, _ := linkFormatter(context)
link = strings.ReplaceAll(link, `"`, `\"`) // breaks tesh test
return link
}),
Lead: note.Lead,

Loading…
Cancel
Save