-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
a11y: warn about href="javascript:void(0)" #4733
Conversation
@@ -428,7 +428,7 @@ export default class Element extends Node { | |||
if (attribute) { | |||
const value = attribute.get_static_value(); | |||
|
|||
if (value === '' || value === '#') { | |||
if (value === '' || value === '#' || /^\W*?javascript/.test(value)) { |
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.
The ?
here after the *
doesn't do anything - and we should be testing for javascript:
, not just javascript
. There's nothing wrong with linking to paths that happen to begin with javascript
.
@@ -428,7 +428,7 @@ export default class Element extends Node { | |||
if (attribute) { | |||
const value = attribute.get_static_value(); | |||
|
|||
if (value === '' || value === '#' || /^\W*?javascript/.test(value)) { | |||
if (value === '' || value === '#' || /^\W*javascript:/.test(value)) { |
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.
A case insensitive check should be done, since URI schemes are case insensitive RFC 2396:
/^\W*javascript:/i.test(value)
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.
thanks for the information!
This has been released in 3.22.0 - thanks! |
Summary
href="javascript:void(0)"
is not recommended for a11y and maybe it would be great if svelte can warn about it.Note
Besides, would it be great to warn about something like:
as well? If so I'm willing to help or have an issue about this.
Tests
npm test
oryarn test
)