Skip to content

Commit 4a51e39

Browse files
flytalytjex
andauthored
fix: escape inner double quotes (#440)
Co-authored-by: tjex <tjex@tjex.net>
1 parent 7ae8a39 commit 4a51e39

File tree

9 files changed

+251
-1
lines changed

9 files changed

+251
-1
lines changed

internal/core/util.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package core
22

3+
import "strconv"
4+
35
// lazyStringer implements Stringer and wait for String() to be called the first
46
// time before computing its value.
57
type lazyStringer struct {
@@ -24,5 +26,5 @@ func (s *lazyStringer) String() string {
2426
}
2527

2628
func (s *lazyStringer) MarshalJSON() ([]byte, error) {
27-
return []byte(`"` + s.String() + `"`), nil
29+
return []byte(strconv.Quote(s.String())), nil
2830
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# zk configuration file
2+
#
3+
# Uncomment the properties you want to customize.
4+
5+
# NOTE SETTINGS
6+
#
7+
# Defines the default options used when generating new notes.
8+
[note]
9+
10+
# Language used when writing notes.
11+
# This is used to generate slugs or with date formats.
12+
#language = "en"
13+
14+
# The default title used for new note, if no `--title` flag is provided.
15+
#default-title = "Untitled"
16+
17+
# Template used to generate a note's filename, without extension.
18+
#filename = "{{id}}"
19+
20+
# The file extension used for the notes.
21+
#extension = "md"
22+
23+
# Template used to generate a note's content.
24+
# If not an absolute path, it is relative to .zk/templates/
25+
template = "default.md"
26+
27+
# Path globs ignored while indexing existing notes.
28+
#ignore = [
29+
# "drafts/*",
30+
# "log.md"
31+
#]
32+
33+
# Configure random ID generation.
34+
35+
# The charset used for random IDs. You can use:
36+
# * letters: only letters from a to z.
37+
# * numbers: 0 to 9
38+
# * alphanum: letters + numbers
39+
# * hex: hexadecimal, from a to f and 0 to 9
40+
# * custom string: will use any character from the provided value
41+
#id-charset = "alphanum"
42+
43+
# Length of the generated IDs.
44+
#id-length = 4
45+
46+
# Letter case for the random IDs, among lower, upper or mixed.
47+
#id-case = "lower"
48+
49+
50+
# EXTRA VARIABLES
51+
#
52+
# A dictionary of variables you can use for any custom values when generating
53+
# new notes. They are accessible in templates with {{extra.<key>}}
54+
[extra]
55+
56+
#key = "value"
57+
58+
59+
# GROUP OVERRIDES
60+
#
61+
# You can override global settings from [note] and [extra] for a particular
62+
# group of notes by declaring a [group."<name>"] section.
63+
#
64+
# Specify the list of directories which will automatically belong to the group
65+
# with the optional `paths` property.
66+
#
67+
# Omitting `paths` is equivalent to providing a single path equal to the name of
68+
# the group. This can be useful to quickly declare a group by the name of the
69+
# directory it applies to.
70+
71+
#[group."<NAME>"]
72+
#paths = ["<DIR1>", "<DIR2>"]
73+
#[group."<NAME>".note]
74+
#filename = "{{format-date now}}"
75+
#[group."<NAME>".extra]
76+
#key = "value"
77+
78+
79+
# MARKDOWN SETTINGS
80+
[format.markdown]
81+
82+
# Format used to generate links between notes.
83+
# Either "wiki", "markdown" or a custom template. Default is "markdown".
84+
#link-format = "wiki"
85+
# Indicates whether a link's path will be percent-encoded.
86+
# Defaults to true for "markdown" format and false for "wiki" format.
87+
#link-encode-path = true
88+
# Indicates whether a link's path file extension will be removed.
89+
# Defaults to true.
90+
#link-drop-extension = true
91+
92+
# Enable support for #hashtags.
93+
hashtags = false
94+
# Enable support for :colon:separated:tags:.
95+
colon-tags = false
96+
# Enable support for Bear's #multi-word tags#
97+
# Hashtags must be enabled for multi-word tags to work.
98+
multiword-tags = false
99+
100+
101+
# EXTERNAL TOOLS
102+
[tool]
103+
104+
# Default editor used to open notes. When not set, the EDITOR or VISUAL
105+
# environment variables are used.
106+
#editor = "vim"
107+
108+
# Pager used to scroll through long output. If you want to disable paging
109+
# altogether, set it to an empty string "".
110+
#pager = "less -FIRX"
111+
112+
# Command used to preview a note during interactive fzf mode.
113+
# Set it to an empty string "" to disable preview.
114+
115+
# bat is a great tool to render Markdown document with syntax highlighting.
116+
#https://github.com/sharkdp/bat
117+
#fzf-preview = "bat -p --color always {-1}"
118+
119+
120+
# LSP
121+
#
122+
# Configure basic editor integration for LSP-compatible editors.
123+
# See https://github.com/zk-org/zk/blob/main/docs/editors-integration.md
124+
#
125+
[lsp]
126+
127+
[lsp.diagnostics]
128+
# Each diagnostic can have for value: none, hint, info, warning, error
129+
130+
# Report titles of wiki-links as hints.
131+
#wiki-title = "hint"
132+
# Warn for dead links between notes.
133+
dead-link = "error"
134+
135+
[lsp.completion]
136+
# Customize the completion pop-up of your LSP client.
137+
138+
# Show the note title in the completion pop-up, or fallback on its path if empty.
139+
#note-label = ""
140+
# Filter out the completion pop-up using the note title or its path.
141+
#note-filter-text = " "
142+
# Show the note filename without extension as detail.
143+
#note-detail = ""
144+
145+
146+
# NAMED FILTERS
147+
#
148+
# A named filter is a set of note filtering options used frequently together.
149+
#
150+
[filter]
151+
152+
# Matches the notes created the last two weeks. For example:
153+
# $ zk list recents --limit 15
154+
# $ zk edit recents --interactive
155+
#recents = "--sort created- --created-after 'last two weeks'"
156+
157+
158+
# COMMAND ALIASES
159+
#
160+
# Aliases are user commands called with `zk <alias> [<flags>] [<args>]`.
161+
#
162+
# The alias will be executed with `$SHELL -c`, please refer to your shell's
163+
# man page to see the available syntax. In most shells:
164+
# * $@ can be used to expand all the provided flags and arguments
165+
# * you can pipe commands together with the usual | character
166+
#
167+
[alias]
168+
# Here are a few aliases to get you started.
169+
170+
# Shortcut to a command.
171+
#ls = "zk list $@"
172+
173+
# Default flags for an existing command.
174+
#list = "zk list --quiet $@"
175+
176+
# Edit the last modified note.
177+
#editlast = "zk edit --limit 1 --sort modified- $@"
178+
179+
# Edit the notes selected interactively among the notes created the last two weeks.
180+
# This alias doesn't take any argument, so we don't use $@.
181+
#recent = "zk edit --sort created- --created-after 'last two weeks' --interactive"
182+
183+
# Print paths separated with colons for the notes found with the given
184+
# arguments. This can be useful to expand a complex search query into a flag
185+
# taking only paths. For example:
186+
# zk list --link-to "`zk path -m potatoe`"
187+
#path = "zk list --quiet --format {{path}} --delimiter , $@"
188+
189+
# Show a random note.
190+
#lucky = "zk list --quiet --format full --sort random --limit 1"
191+
192+
# Returns the Git history for the notes found with the given arguments.
193+
# Note the use of a pipe and the location of $@.
194+
#hist = "zk list --format path --delimiter0 --quiet $@ | xargs -t -0 git log --patch --"
195+
196+
# Edit this configuration file.
197+
#conf = '$EDITOR "$ZK_NOTEBOOK_DIR/.zk/config.toml"'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# {{title}}
2+
3+
{{content}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: no quoted word in title
3+
date: 2024-05-10
4+
---
5+
6+
This note should _not_ break json graph output, and it doesn't (2024-05-10).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
date: 2024-05-10
3+
---
4+
5+
# quoted "word" in h1 title
6+
7+
This note should _not_ break json graph output, and it _does_ (2024-05-10).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: quoted "word" in yaml title
3+
date: 2024-05-10
4+
---
5+
6+
This note should _not_ break json graph output, and it _does_ (2024-05-10).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
date: 2024-05-10
3+
---
4+
5+
# quoted 'word' in h1 title
6+
7+
This note should _not_ break json graph output, and it doesn't (2024-05-10).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: quoted 'word' in h1 title
3+
date: 2024-05-10
4+
---
5+
6+
This note should _not_ break json graph output, and it doesn't (2024-05-10).

tests/issue-389.tesh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$ cd issue-389
2+
3+
# should output valid json. Currently term ENV variables are printed to stdout
4+
$ zk graph -q --format json
5+
>{
6+
> "notes": [
7+
> {"filename":"no-quotes-in-title.md","filenameStem":"no-quotes-in-title","path":"no-quotes-in-title.md","absPath":"{{working-dir}}/no-quotes-in-title.md","title":"no quoted word in title","link":"[no quoted word in title](no-quotes-in-title)","lead":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","body":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","snippets":["This note should _not_ break json graph output, and it doesn't (2024-05-10)."],"rawContent":"---\ntitle: no quoted word in title\ndate: 2024-05-10\n---\n\nThis note should _not_ break json graph output, and it doesn't (2024-05-10).\n","wordCount":22,"tags":[],"metadata":{"date":"2024-05-10","title":"no quoted word in title"},"created":"2024-05-10T00:00:00Z","modified":"{{match '[\-T\.\:0-9]+'}}Z","checksum":"c2590b3a4381b0fd5f2d9309ef54b17e3dff0aa12f07cdbc89e3afcd50aa4e98"},
8+
> {"filename":"quotes-in-h1-title.md","filenameStem":"quotes-in-h1-title","path":"quotes-in-h1-title.md","absPath":"{{working-dir}}/quotes-in-h1-title.md","title":"quoted \"word\" in h1 title","link":"[quoted \"word\" in h1 title](quotes-in-h1-title)","lead":"This note should _not_ break json graph output, and it _does_ (2024-05-10).","body":"This note should _not_ break json graph output, and it _does_ (2024-05-10).","snippets":["This note should _not_ break json graph output, and it _does_ (2024-05-10)."],"rawContent":"---\ndate: 2024-05-10\n---\n\n# quoted \"word\" in h1 title\n\nThis note should _not_ break json graph output, and it _does_ (2024-05-10).\n","wordCount":22,"tags":[],"metadata":{"date":"2024-05-10"},"created":"2024-05-10T00:00:00Z","modified":"{{match '[\-T\.\:0-9]+'}}Z","checksum":"3701543d5a66b3d3751f31fe9890eb73b45c316531a29c6b59ed18b4f4e0c0e5"},
9+
> {"filename":"quotes-in-yaml-title.md","filenameStem":"quotes-in-yaml-title","path":"quotes-in-yaml-title.md","absPath":"{{working-dir}}/quotes-in-yaml-title.md","title":"quoted \"word\" in yaml title","link":"[quoted \"word\" in yaml title](quotes-in-yaml-title)","lead":"This note should _not_ break json graph output, and it _does_ (2024-05-10).","body":"This note should _not_ break json graph output, and it _does_ (2024-05-10).","snippets":["This note should _not_ break json graph output, and it _does_ (2024-05-10)."],"rawContent":"---\ntitle: quoted \"word\" in yaml title\ndate: 2024-05-10\n---\n\nThis note should _not_ break json graph output, and it _does_ (2024-05-10).\n","wordCount":22,"tags":[],"metadata":{"date":"2024-05-10","title":"quoted \"word\" in yaml title"},"created":"2024-05-10T00:00:00Z","modified":"{{match '[\-T\.\:0-9]+'}}Z","checksum":"3a27fa46a7f7a3ae9f69a416d1868925d3f64fedce18f8c6bb8fa2f8a696769a"},
10+
> {"filename":"single-quotes-in-h1-title.md","filenameStem":"single-quotes-in-h1-title","path":"single-quotes-in-h1-title.md","absPath":"{{working-dir}}/single-quotes-in-h1-title.md","title":"quoted 'word' in h1 title","link":"[quoted 'word' in h1 title](single-quotes-in-h1-title)","lead":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","body":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","snippets":["This note should _not_ break json graph output, and it doesn't (2024-05-10)."],"rawContent":"---\ndate: 2024-05-10\n---\n\n# quoted 'word' in h1 title\n\nThis note should _not_ break json graph output, and it doesn't (2024-05-10).\n","wordCount":22,"tags":[],"metadata":{"date":"2024-05-10"},"created":"2024-05-10T00:00:00Z","modified":"{{match '[\-T\.\:0-9]+'}}Z","checksum":"5170dfeba776aabfa57d96d373d4db74e4e168c9e9a6256e28d7d049d966c173"},
11+
> {"filename":"single-quotes-in-yaml-title.md","filenameStem":"single-quotes-in-yaml-title","path":"single-quotes-in-yaml-title.md","absPath":"{{working-dir}}/single-quotes-in-yaml-title.md","title":"quoted 'word' in h1 title","link":"[quoted 'word' in h1 title](single-quotes-in-yaml-title)","lead":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","body":"This note should _not_ break json graph output, and it doesn't (2024-05-10).","snippets":["This note should _not_ break json graph output, and it doesn't (2024-05-10)."],"rawContent":"---\ntitle: quoted 'word' in h1 title\ndate: 2024-05-10\n---\n\nThis note should _not_ break json graph output, and it doesn't (2024-05-10).\n","wordCount":22,"tags":[],"metadata":{"date":"2024-05-10","title":"quoted 'word' in h1 title"},"created":"2024-05-10T00:00:00Z","modified":"{{match '[\-T\.\:0-9]+'}}Z","checksum":"a5ccc8085070bb796c81aec07b31002aaddd474006865334f0c83f54fd1c85c1"}
12+
> ],
13+
> "links": [
14+
>
15+
> ]
16+
>}

0 commit comments

Comments
 (0)