fix: correct www autofix in no-bare-urls - #720
Conversation
no-bare-urls
lumirlumir
left a comment
There was a problem hiding this comment.
Disclosure: I'm a participant of open source contribution program OSSCA: confirmed.
Thanks for the PR. I’ve left a few comments about incorrect autofix cases.
There was a problem hiding this comment.
GFM allows any character other than whitespace and < after the domain, and Example 626 treats the following entire URL as a valid autolink:
www.google.com/search?q=(business))+okThe current autofix produces:
[www.google.com/search?q=(business))+ok](http://www.google.com/search?q=(business))+ok)When parsed again, the actual link destination is truncated to:
http://www.google.com/search?q=(business)
This happens because CommonMark requires parentheses in a link destination without angle brackets to be escaped or balanced. Similarly, after autofixing www.example.com/a\*b, the backslash is interpreted as a backslash escape, changing the URL to /a*b. In other words, the autofix silently changes valid URLs to different destinations.
There was a problem hiding this comment.
Another incorrect autofix behavior occurs when autofixing the following valid GFM input:
www.example.com/a]bproduces invalid link text:
[www.example.com/a]b](http://www.example.com/a]b)I reproduced an issue where no-bare-urls throws Custom getRange() method must be implemented in the subclass during ESLint’s next autofix pass.
Additionally, after autofixing www.example.com/a*b*c and www.example.com/a~b~c, characters in the label are parsed as emphasis and strikethrough, respectively, changing the rendered output. The link text need to be escaped separately from the destination. CommonMark explicitly requires brackets within link text to be either backslash-escaped or part of a matched pair per the link text definition and Examples 528–529.
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
Fix the incorrect autofix for
wwwautolinks.What changes did you make? (Give an overview)
Updated
no-bare-urlsto convertwww.example.cominto[www.example.com](http://www.example.com).Added a test for the autofix result.
Related Issues
Fixes #710
Is there anything you'd like reviewers to focus on?
Nothing in particular.
Disclosure: I'm a participant of open source contribution program OSSCA