Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(summary): escape ws_root special characters #1012

Merged
merged 2 commits into from
Sep 13, 2023
Merged

fix(summary): escape ws_root special characters #1012

merged 2 commits into from
Sep 13, 2023

Conversation

git-girl
Copy link
Contributor

@git-girl git-girl commented Aug 5, 2023

hey there :)

i was just trying to debug the links in the summary module not being generated properly.
the issue is that the links are generated as ones relative to current workspace root
( the format of :$/path/from/current/workspace:).
however the actuals paths post gsub remain full paths.
for debugging i modified the module.lua like so:

local norgname = filename:match("(.+)%.norg$") -- strip extension for link destinations
vim.print("looking at file: " .. filename)
if not norgname then
    -- NOTE: either here
    vim.print("DEBUG: treated it as a non norg file")
    norgname = filename
end
-- NOTE: or here
norgname = norgname:gsub("^" .. ws_root, "")
vim.print("post gsub: " .. norgname )

and that gave me this:

   looking at file: /home/cherry-cat/Notes/General/index.norg
   post gsub: /home/cherry-cat/Notes/General/index
   looking at file: /home/cherry-cat/Notes/General/coding/debugging_neorg_auto_cats.norg
   post gsub: /home/cherry-cat/Notes/General/coding/debugging_neorg_auto_cats
   looking at file: /home/cherry-cat/Notes/General/coding/debugging_neorg_telescope.norg
   post gsub: /home/cherry-cat/Notes/General/coding/debugging_neorg_telescope
   looking at file: /home/cherry-cat/Notes/General/coding/debugging_telescope_cc_dressing.norg
   post gsub: /home/cherry-cat/Notes/General/coding/debugging_telescope_cc_dressing
   looking at file: /home/cherry-cat/Notes/General/coding/factory_pattern.norg
   post gsub: /home/cherry-cat/Notes/General/coding/factory_pattern

and so on for every file. \
with ws_root being: /home/cherry-cat/Notes/General \

i figured out that the issue lies in the special character
in my user name not being escaped (._.)

so i added this bit here before the norgname

local escaped_ws_root = ws_root:gsub("([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")
norgname = string.gsub(norgname,"^" .. escaped_ws_root, "")

i am legit the worst at regex. and idk if these characters can even be part of a path so probably it's good if someone reads this regex.

sorry also for not opening an issue i guess. i thought maybe this is ok because its just 2 lines that are changed pretty straight forwardly.

best regards 👋

Co-authored-by: TerryQ <12786477+TerryQuiet@users.noreply.github.com>
Copy link
Member

@NTBBloodbath NTBBloodbath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you so much for this patch!

@NTBBloodbath NTBBloodbath merged commit 32abc0d into nvim-neorg:main Sep 13, 2023
1 check passed
benlubas pushed a commit to benlubas/neorg that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants