xwmx / nb

CLI and local web plain text note‑taking, bookmarking, and archiving with linking, tagging, filtering, search, Git versioning & syncing, Pandoc conversion, + more, in a single portable script.
https://xwmx.github.io/nb
GNU Affero General Public License v3.0
6.43k stars 181 forks source link

(Updated) Links inside notes to other notes with special characters in the title can't be followed #260

Closed borjarobert closed 11 months ago

borjarobert commented 11 months ago

I'm having trouble navigating through my notes when I try to follow links if their titles have non-English characters like áéíóú.

This only happens when the links are inside of a note, connecting to a different one. The problem seems to be related to the URL generated for them.

To replicate:

$ nb add --title "Noté one" --content "test"
# Please note the *é* in the title
$ nb add --title "Note two no special characters" --content "I link [[Noté one]] from here"
$ nb
--------------------------------------
[2] Note two no special characters
[1] Noté one
--------------------------------------

With this setting, if I run nb b I can visit both links and both work fine. But if I visit nb b 2 and try to follow the link to Noté one it will point to http://localhost:6789/notebook:Noté one, fail and show a 404 error.

Some URLs to link notes are created using their id and follow the pattern http://localhost:6789/notebook_name:note_id. This is used both for the main list of notes when you run nb b and while linking notes to themselves. These work perfectly fine.

Some other URLs, like the ones linking one note to a different one, follow a different pattern which looks like http://localhost:6789/notebook_name:note_title. These only work when no special characters are on the title.

There may be reasons for having two different URL patterns but I'd like to suggest sticking only to the one using the note id (and maybe including the #note-title-with-hyphens afterwards so you can see in the address bar what note are you browsing). AFAICT it is the default behaviour when a note has a link to itself, although I don't know if there would be any unintended side effects I'm not seeing.

I have updated the Issue to (hopefully) give a clearer explanation of what is happening and to provide an easy way to replicate. I'm loving nb so much.

xwmx commented 11 months ago

@borjarobert Glad you like it! Thanks for the detailed information. I was able to resolve this by improving the URI encoding / decoding when handling the request. These changes are available in version 7.5.3.

Regarding the linking behavior, [[wiki-style links]] are turned into HTML links via the _resolve_links() function, which wraps them in URLs using the selector specified in the brackets, without converting it to an id selector first. This allows users to identify items within [[wiki-style links]] and URLs using any of the selector formats supported, and it avoids the performance penalty required to look up selectors during rending.

Please let me know if you run into any additional issues with this.

borjarobert commented 11 months ago

Thank you so much! It works great!

Also, thank you for the explanation.