hexojs / hexo-renderer-marked

Markdown renderer for Hexo
MIT License
179 stars 94 forks source link

`[]` in urls are not escaped #268

Closed njzjz closed 7 months ago

njzjz commented 1 year ago
* [2-2 分析数据](https://bf.njzjz.win/ecnuchemistry/分析化学与分析技术(I)/课件-2-2%20第二章%20分析数据的处理和质量保证%20[兼容模式].pdf)
* [2-3 分析数据](https://bf.njzjz.win/ecnuchemistry/分析化学与分析技术(I)/课件-2-3%20第二章%20分析数据的处理和质量保证%20[兼容模式].pdf)
* [2-4 分析数据](https://bf.njzjz.win/ecnuchemistry/分析化学与分析技术(I)/课件-2-4%20第二章%20分析数据的处理和质量保证%20[兼容模式].pdf)

GitHub renders it as:

The actual link in the source code is: https://bf.njzjz.win/ecnuchemistry/%E5%88%86%E6%9E%90%E5%8C%96%E5%AD%A6%E4%B8%8E%E5%88%86%E6%9E%90%E6%8A%80%E6%9C%AF(I)/%E8%AF%BE%E4%BB%B6-2-2%20%E7%AC%AC%E4%BA%8C%E7%AB%A0%20%E5%88%86%E6%9E%90%E6%95%B0%E6%8D%AE%E7%9A%84%E5%A4%84%E7%90%86%E5%92%8C%E8%B4%A8%E9%87%8F%E4%BF%9D%E8%AF%81%20%5B%E5%85%BC%E5%AE%B9%E6%A8%A1%E5%BC%8F%5D.pdf

However, hexo-renderer-marked renders the URL as:

https://bb.njzjz.win/file/jinzhe/ecnuchemistry/%E5%88%86%E6%9E%90%E5%8C%96%E5%AD%A6%E4%B8%8E%E5%88%86%E6%9E%90%E6%8A%80%E6%9C%AF(I)/%E8%AF%BE%E4%BB%B6-2-2%20%E7%AC%AC%E4%BA%8C%E7%AB%A0%20%E5%88%86%E6%9E%90%E6%95%B0%E6%8D%AE%E7%9A%84%E5%A4%84%E7%90%86%E5%92%8C%E8%B4%A8%E9%87%8F%E4%BF%9D%E8%AF%81%20[%E5%85%BC%E5%AE%B9%E6%A8%A1%E5%BC%8F].pdf

[] are not escaped, causing a 404 error.

tomap commented 1 year ago

The char ] should be escaped into %5D Same for the [ which should be %5B

There might be another way to escape those....

uiolee commented 11 months ago

According to RFC3986, square brackets is acceptable for URI. I'm not sure if hexo should make changes.

WHATWG URL API doesn't escape square brackets, but encodeURI() does.

njzjz commented 11 months ago

RFC3986 says

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.

To my understanding, it only allows squared brackets used in a host like http://[2607:f8b0:4005:802::1007]/. Other usage is disallowed.

njzjz commented 8 months ago

The char ] should be escaped into %5D Same for the [ which should be %5B

As a workaround, I manually replace [ and ] in the links with %5B and %5D, respectively, and it works. However, the link in the source code is hard to read.