medialize / URI.js

Javascript URL mutation library
http://medialize.github.io/URI.js/
MIT License
6.26k stars 474 forks source link

uri.withinString fails on markdown links #360

Open arj03 opened 7 years ago

arj03 commented 7 years ago

Doing

uri.withinString(msg.value.content.text, (link) => {

gives me:

dat://blog.tableflip.io/](dat://blog.tableflip.io/

for

[dat://blog.tableflip.io/](dat://blog.tableflip.io/) is a thing

But ] should not be a valid character in a URL according to rfc1738.txt

rodneyrehm commented 7 years ago

I can confirm the problem.

var s = 'good markdown [link](dat://blog.tableflip.io/) pointless markdown [dat://blog.tableflip.io/](dat://blog.tableflip.io/) is a thing';
URI.withinString(s, x => `<a>${x}</a>`)
// "good markdown [link](<a>dat://blog.tableflip.io/</a>) pointless markdown [<a>dat://blog.tableflip.io/](dat://blog.tableflip.io/)</a> is a thing"

The problem is somewhere in https://github.com/medialize/URI.js/blob/master/src/URI.js#L1019-L1034


Since you mentioned RFC 1738 it should probably be pointed out that said RFC was superseded by RFC 3986. ] is in gen-delims and thus in the reserved character group, so should not be used in an URI unescaped, unless it's part of the IPv6 notation (Appendix D.1). Unfortunately many people didn't get that memo, leading to loads of links including query strings like ?foo[1]=bar.