Skip to content

Commit

Permalink
Fix URL encoding for space characters (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
gplusplus314 authored Nov 25, 2022
1 parent bba79cd commit af986a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed bug with `Note.from_lines` where the given path would be modified in place to be relative to the root, which caused a bug in `:ObsidianFollowLink`.
- Completion for creating new notes via nvim-cmp is now aware of daily notes, so when you start typing todays date in the form of YYYY-MM-DD, you get a "Create new" completion option for today's daily note if it doesn't exist yet.
- Fixed bug where `:ObsidianOpen` blocked the NeoVim UI on Linux.
- Fixed URL encoding of space characters for better compatibility with external applications.

## [v1.6.1](https://github.com/epwalsh/obsidian.nvim/releases/tag/v1.6.1) - 2022-10-17

Expand Down
7 changes: 6 additions & 1 deletion lua/obsidian/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ util.urlencode = function(str)
local url = str
url = url:gsub("\n", "\r\n")
url = url:gsub("([^%w _%%%-%.~])", char_to_hex)
url = url:gsub(" ", "+")

-- Spaces in URLs are always safely encoded with `%20`, but not always safe
-- with `+`. For example, `+` in a query param's value will be interpreted
-- as a literal plus-sign if the decoder is using JavaScript's `decodeURI`
-- function.
url = url:gsub(" ", "%%20")
return url
end

Expand Down
2 changes: 1 addition & 1 deletion test/obsidian/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local util = require "obsidian.util"

describe("obsidian.util", function()
it("should correctly URL-encode a path", function()
assert.equals(util.urlencode [[~/Library/Foo Bar.md]], [[~%2FLibrary%2FFoo+Bar.md]])
assert.equals(util.urlencode [[~/Library/Foo Bar.md]], [[~%2FLibrary%2FFoo%20Bar.md]])
end)
it("should match case of key to prefix", function()
assert.equals(util.match_case("Foo", "foo"), "Foo")
Expand Down

0 comments on commit af986a0

Please sign in to comment.