Skip to content

Commit 217f7c7

Browse files
authored
Fix YAML parsing issues with unquoted URLs (#348)
Fixes #347.
1 parent 194f9fc commit 217f7c7

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Changed API of client methods `Client:find_tags()` and `Client:find_tags_async()`. The return value (or value passed to the callback) is now a list of objects representing the location of tags found. These objects have the following fields: `tag: string`, `path: string|Path`, `line: integer`.
1717

18+
### Fixed
19+
20+
- Fixed a YAML parsing issue with unquoted URLs in an array item.
21+
1822
## [v2.7.1](https://github.com/epwalsh/obsidian.nvim/releases/tag/v2.7.1) - 2024-01-23
1923

2024
### Fixed

lua/obsidian/yaml/native.lua

+9-1
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,16 @@ end
216216
Parser._try_parse_field = function(self, lines, i, text)
217217
local line = lines[i]
218218
text = text and text or util.strip_comments(line.content)
219+
219220
local _, key, value
220-
_, _, key, value = string.find(text, "([a-zA-Z0-9_-]+):(.*)")
221+
222+
-- First look for start of mapping, array, block, etc, e.g. 'foo:'
223+
_, _, key = string.find(text, "([a-zA-Z0-9_-]+):$")
224+
if not key then
225+
-- Then try inline field, e.g. 'foo: bar'
226+
_, _, key, value = string.find(text, "([a-zA-Z0-9_-]+): (.*)")
227+
end
228+
221229
value = value and util.strip_whitespace(value) or nil
222230
if value == "" then
223231
value = nil

test/obsidian/yaml/parser_spec.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ describe("Parser class", function()
201201
local result = parser:parse(table.concat({
202202
"aliases:",
203203
' - "Research project: staged training"',
204+
"sources:",
205+
" - https://example.com",
204206
}, "\n"))
205-
assert.are_same({ aliases = { "Research project: staged training" } }, result)
207+
assert.are_same({ aliases = { "Research project: staged training" }, sources = { "https://example.com" } }, result)
206208
end)
207209
end)

0 commit comments

Comments
 (0)