stefanopagliari / bibnotes

359 stars 30 forks source link

path error (automatically replace '\\' with '%5C') #109

Closed 1qzhworld closed 2 years ago

1qzhworld commented 2 years ago

Hi, I an working on windows 10 and Obsidian v0.14.15, with the latest bibnotes (i.e. bibnotes-0.9.159).

The placeholder {{localLibraryLink}} and {{file}} do not work well. For example, when I set the template

Attachments: {{file}}
[Local Library]({{localLibraryLink}})

The result is something like

Attachment: [blabla](file://D:%5C2021%5CHazan2012.pdf)
[Local Library]((zotero://select/library/items/9JUGK88))
You can see that the path of attachment and the format of local library are both wrong. Placeholder Supposed Shows
{{file}} file://D:/2021/Hazan2012.pdf file://D:%5C2021%5CHazan2012.pdf
{{localLibraryLink}} zotero://select/library/items/9JUGK88 (zotero://select/library/items/9JUGK88)

However, the contents in the JSON file are correct, i.e., D:\\2021\\Hazan2012.pdf and zotero://select/library/items/9JUGK88.

I am not sure why this happens. It works in the morning, but fails in the night, Currently, even the default plain selected tempalte shows the same problem, though I did not modify the source code. Is there any suggestion? Thanks!

stefanopagliari commented 2 years ago

@1qzhworld Did the plugin exported the path correctly in earlier versions? I do not have access to a computer running Windows, so I have difficulties testing the way paths are generated in this operating system, but I will try to identify what is the source of the issue

1qzhworld commented 2 years ago

@1qzhworld Did the plugin exported the path correctly in earlier versions? I do not have access to a computer running Windows, so I have difficulties testing the way paths are generated in this operating system, but I will try to identify what is the source of the issue

Yes, I believe that it worked well at the begining, but failed afterwards... I have installed and unstalled some other plugins after it works (but I don't remember the details). Would Bibnotes formatter influenced by other setting?

Anyway, thanks for your contribution!

1qzhworld commented 2 years ago

I am not sure whether it worked (perhaps never worked). I have renew a new obsidian vault and tested the Bibnotes formatter plugin. But unfortunately, it fails.

I have searched similar problems in Google and I think the following problems are related and should be helpful. https://security.stackexchange.com/questions/162940/function-of-5c-in-a-path-traversal https://stackoverflow.com/questions/608453/c-sharp-urldecode-turns-5c-into-instead-of

In my case, / is replaced by %5C and ` (blank) is replaced by%2050`.

Hope the observations are helpful.

stefanopagliari commented 2 years ago

@1qzhworld Thank you. I will look into this

OxygenFrost commented 2 years ago

I think I have a related issue/insight on windows 10, bibnotes v 0.9.20, Obsidian v0.15.6. Sorry if this is poor formatting, I'm very new at this

I checked the nonfunctional {{file}} link against a working external link made via Obsidian's built in Ctrl+ drag and drop.

Link generated from BibNotes Formatter {{file}}

[cross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf](file://C:%5CZoteroDocuments%5CBMJ%2520Global%2520Health2021%5Ccross_et_al_2021_who_funded_the_research_behind_the_oxford%E2%80%93astrazeneca_covid-19_vaccine.pdf); [PubMed entry](file://)

Link generated by Ctrl-drag and dropping pdf file from Windows file explorer into Obsidian

[cross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf](file:///C:%5CZoteroDocuments%5CBMJ%20Global%20Health2021%5Ccross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf)

The file name as I see it in Windows is:

C:\ZoteroDocuments\BMJ Global Health2021\cross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf

Differences Bibnotes Formatter Obsidian
en dash(–) encoding oxford%E2%80%93astrazeneca oxford–astrazeneca
Number of / after (file: (file:// (file:///
Space encoding BMJ%2520Global BMJ%20Global
OxygenFrost commented 2 years ago

Further clarification/investigation: For me, all of the links gnerated by {{file}} were broken. Some of them (underscores and letters in file name only, e.g. "david_allen_2001_getting_things_done.pdf") started working when I manually changed the {{file}} link to start with (file:/// instead of (file:// .

Following this, I tried a few variations on the above and found that the en dash encoding isn't the issue, but the spaces in the file names. (see line 3 of above table in previous comment) The following link works now [cross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf](file:///C:%5CZoteroDocuments%5CBMJ%20Global%20Health2021%5Ccross_et_al_2021_who_funded_the_research_behind_the_oxford%E2%80%93astrazeneca_covid-19_vaccine.pdf)

stefanopagliari commented 2 years ago

@OxygenFrost Thank you for flagging this problem. I had inadvertently created the problem while trying to fix another encoding issue recently. Could you please check if this is sorted in 0.9.201?

stefanopagliari commented 2 years ago

@OxygenFrost I'm closing this issue but please reopen it if the problem is not solved by the latest version of the plugin

1qzhworld commented 2 years ago

Further clarification/investigation: For me, all of the links gnerated by {{file}} were broken. Some of them (underscores and letters in file name only, e.g. "david_allen_2001_getting_things_done.pdf") started working when I manually changed the {{file}} link to start with (file:/// instead of (file:// .

Following this, I tried a few variations on the above and found that the en dash encoding isn't the issue, but the spaces in the file names. (see line 3 of above table in previous comment) The following link works now [cross_et_al_2021_who_funded_the_research_behind_the_oxford–astrazeneca_covid-19_vaccine.pdf](file:///C:%5CZoteroDocuments%5CBMJ%20Global%20Health2021%5Ccross_et_al_2021_who_funded_the_research_behind_the_oxford%E2%80%93astrazeneca_covid-19_vaccine.pdf)

@OxygenFrost Does the latest version 0.9.207 work for you? I still get same troubles. If you also suffer this problem, let's reopen it?