markdown-it / mdurl

URL utilities for markdown-it

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

URI support

christianbundy opened this issue · comments

Hello!

This module has been working great for me, but we're working with non-URLs like mailto:, magnet:, and dat: where the URI path is being parsed as a host. You can find more information in ssbc/ssb-markdown#25, but would it be possible to support non-URL URIs in this module?

Thanks!

This module supports all valid schemas. I you think opposite - please provide a minimal code sample to prove.

If you have problems with markdown - check markdown's link validator first, it's very restrictive for security reasons.

Thanks for the quick response!

800px-uri_syntax_diagram

const mdurl = require('mdurl')
console.log(mdurl.parse('scheme:path'))
/* => Url {
  protocol: 'scheme:',
  slashes: null,
  auth: null,
  port: null,
  hostname: 'path',
  hash: null,
  search: null,
  pathname: null }
*/

As you can see, the path is being incorrectly parsed as the host.

It looks like this problem also happens with minimal URNs like urn:sha1, but doesn't affect data URIs like data:, because they have a comma. Another useful example might be urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C, where sha1 is parsed as a hostname:

{
  protocol: 'urn:',
  slashes: null,
  auth: null,
  port: null,
  hostname: 'sha1',
  hash: null,
  search: null,
  pathname: ':YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C'
}

Did you compared behaviour with native require('url')? This one was forked for very specific reasons:

  • keep tailing / somewhere
  • crash-less encode/decode

Everything else should be the same, and there are no plans to diverge.

Thanks for the recommendation. I can confirm that the problem exists with require('url'), which is Node's legacy API, but that the bug is resolved when using new URL rather than url.parse().

Would you be open to upgrading away from the legacy API to bring this up-to-date?

Alternatively, would it be better to upgrade markdown-it to use the non-legacy API instead? My goal is to fix this bug but I'm not sure which option would be best. Thanks for your help!

I'd prefer to keep things without changes if possible.