-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: external link ignore mailto: & javascript: #3812
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,23 +208,27 @@ describe('External link - post', () => { | |
'# External link test', | ||
'1. External link', | ||
'<a href="https://hexo.io/">Hexo</a>', | ||
'2. External link with "rel" Attribute', | ||
'2. Link with hash (#), mailto: , javascript: shouldn\'t be processed', | ||
'<a href="#top">Hexo</a>', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
'<a href="mailto:[email protected]">Hexo</a>', | ||
'<a href="javascript:alert(\'Hexo is awesome!\');">Hexo</a>', | ||
'3. External link with "rel" Attribute', | ||
'<a rel="external" href="https://hexo.io/">Hexo</a>', | ||
'<a href="https://hexo.io/" rel="external">Hexo</a>', | ||
'<a rel="noopenner" href="https://hexo.io/">Hexo</a>', | ||
'<a href="https://hexo.io/" rel="noopenner">Hexo</a>', | ||
'<a rel="external noopenner" href="https://hexo.io/">Hexo</a>', | ||
'<a href="https://hexo.io/" rel="external noopenner">Hexo</a>', | ||
'3. External link with Other Attributes', | ||
'4. External link with Other Attributes', | ||
'<a class="img" href="https://hexo.io/">Hexo</a>', | ||
'<a href="https://hexo.io/" class="img">Hexo</a>', | ||
'4. Internal link', | ||
'5. Internal link', | ||
'<a href="/archives/foo.html">Link</a>', | ||
'5. Ignore links have "target" attribute', | ||
'6. Ignore links have "target" attribute', | ||
'<a href="https://hexo.io/" target="_blank">Hexo</a>', | ||
'6. Ignore links don\'t have "href" attribute', | ||
'7. Ignore links don\'t have "href" attribute', | ||
'<a>Anchor</a>', | ||
'7. Ignore links whose hostname is same as config', | ||
'8. Ignore links whose hostname is same as config', | ||
'<a href="https://example.com">Example Domain</a>' | ||
].join('\n'); | ||
|
||
|
@@ -235,23 +239,27 @@ describe('External link - post', () => { | |
'# External link test', | ||
'1. External link', | ||
'<a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>', | ||
'2. External link with "rel" Attribute', | ||
'2. Link with hash (#), mailto: , javascript: shouldn\'t be processed', | ||
'<a href="#top">Hexo</a>', | ||
'<a href="mailto:[email protected]">Hexo</a>', | ||
'<a href="javascript:alert(\'Hexo is awesome!\');">Hexo</a>', | ||
'3. External link with "rel" Attribute', | ||
'<a rel="external noopener" href="https://hexo.io/" target="_blank">Hexo</a>', | ||
'<a href="https://hexo.io/" target="_blank" rel="external noopener">Hexo</a>', | ||
'<a rel="noopenner" href="https://hexo.io/" target="_blank">Hexo</a>', | ||
'<a href="https://hexo.io/" target="_blank" rel="noopenner">Hexo</a>', | ||
'<a rel="external noopenner" href="https://hexo.io/" target="_blank">Hexo</a>', | ||
'<a href="https://hexo.io/" target="_blank" rel="external noopenner">Hexo</a>', | ||
'3. External link with Other Attributes', | ||
'4. External link with Other Attributes', | ||
'<a class="img" href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>', | ||
'<a href="https://hexo.io/" target="_blank" rel="noopener" class="img">Hexo</a>', | ||
'4. Internal link', | ||
'5. Internal link', | ||
'<a href="/archives/foo.html">Link</a>', | ||
'5. Ignore links have "target" attribute', | ||
'6. Ignore links have "target" attribute', | ||
'<a href="https://hexo.io/" target="_blank">Hexo</a>', | ||
'6. Ignore links don\'t have "href" attribute', | ||
'7. Ignore links don\'t have "href" attribute', | ||
'<a>Anchor</a>', | ||
'7. Ignore links whose hostname is same as config', | ||
'8. Ignore links whose hostname is same as config', | ||
'<a href="https://example.com">Example Domain</a>' | ||
].join('\n')); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are countless of types (
data:
,vbscript:
and so on), can test whether it's a link protocol (http/ftp) or not by testing whetherURL(href).origin
is null. SeeencodeURL()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will change to that.
It required WHATWG URL API. I might mitgate external_link filter to use it in this PR.