Skip to content

Commit

Permalink
Fix bug with YAML parser
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Apr 1, 2024
1 parent c5c4088 commit a7e2ec9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Ensure fields transferred to new note when cloning from template.
- Fixed bug with YAML parser where it would fail to parse field names with spaces in them.
- Fixed bug with YAML parser where it would incorrectly identity comments.

## [v3.7.5](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.5) - 2024-03-22

Expand Down
4 changes: 2 additions & 2 deletions lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,10 @@ end
---@param str string
---@return string
util.strip_comments = function(str)
if vim.startswith(str, "#") then
if vim.startswith(str, "# ") then
return ""
elseif not util.has_enclosing_chars(str) then
return select(1, string.gsub(str, [[%s+#.*$]], ""))
return select(1, string.gsub(str, [[%s+#%s.*$]], ""))
else
return str
end
Expand Down
8 changes: 8 additions & 0 deletions test/obsidian/yaml/parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,12 @@ describe("Parser class", function()
}, "\n"))
assert.are_same({ aliases = { "Research project: staged training" }, sources = { "https://example.com" } }, result)
end)

it("should parse array item strings with '#' in them", function()
local result = parser:parse(table.concat({
"tags:",
" - #demo",
}, "\n"))
assert.are_same({ tags = { "#demo" } }, result)
end)
end)

0 comments on commit a7e2ec9

Please sign in to comment.