Skip to content

Remove javascript: URLs #2829

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

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ module.exports = {
},
},
],
// javascript:void(0) is present in SLDS markup
'no-script-url': 'off',
// _ is not really private.
'no-underscore-dangle': ['error', { allowAfterThis: true }],
//
Expand Down Expand Up @@ -247,7 +245,7 @@ module.exports = {
// TODO: Should be removed
'react/no-deprecated': 'off',

// javascript:void(0) is present in SLDS markup
// <a href="#"> is present in SLDS markup
'jsx-a11y/anchor-is-valid': 'off',
'jsx-a11y/aria-activedescendant-has-tabindex': 2,
'jsx-a11y/interactive-supports-focus': 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports[`DOM snapshots SLDSAlert Custom Class Names 1`] = `
Logged in as John Smith (johnsmith@acme.com).

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
Log out
Expand Down Expand Up @@ -102,7 +102,7 @@ exports[`DOM snapshots SLDSAlert Custom Styles 1`] = `
Logged in as John Smith (johnsmith@acme.com).

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
Log out
Expand Down Expand Up @@ -146,7 +146,7 @@ exports[`DOM snapshots SLDSAlert Dismissable 1`] = `
Logged in as John Smith (johnsmith@acme.com).

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
Log out
Expand Down Expand Up @@ -211,7 +211,7 @@ exports[`DOM snapshots SLDSAlert Error 1`] = `
Your browser is currently not supported. Your Salesforce may be degraded.

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
More Information
Expand Down Expand Up @@ -255,7 +255,7 @@ exports[`DOM snapshots SLDSAlert Info 1`] = `
Logged in as John Smith (johnsmith@acme.com).

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
Log out
Expand Down Expand Up @@ -299,7 +299,7 @@ exports[`DOM snapshots SLDSAlert Offline 1`] = `
You are in offline mode.

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
More information
Expand Down Expand Up @@ -343,7 +343,7 @@ exports[`DOM snapshots SLDSAlert Warning 1`] = `
Your browser is outdated. Your Salesforce experience may be degraded.

<a
href="javascript:void(0);"
href="#"
onClick={[Function]}
>
More Information
Expand Down
7 changes: 4 additions & 3 deletions components/alert/__examples__/close-alert.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand Down Expand Up @@ -33,10 +35,9 @@ class Example extends React.Component {
heading: 'Logged in as John Smith (johnsmith@acme.com).',
headingLink: 'Log out',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
onRequestClose={() => {
action('onRequestClose')();
this.setState({ isOpen: false });
}}
/>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/custom-class-name.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand All @@ -16,9 +18,7 @@ class Example extends React.Component {
heading: 'Logged in as John Smith (johnsmith@acme.com).',
headingLink: 'Log out',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
/>
</AlertContainer>
</IconSettings>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/custom-style.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand All @@ -16,9 +18,7 @@ class Example extends React.Component {
heading: 'Logged in as John Smith (johnsmith@acme.com).',
headingLink: 'Log out',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
/>
</AlertContainer>
</IconSettings>
Expand Down
7 changes: 4 additions & 3 deletions components/alert/__examples__/dismissable.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand All @@ -25,10 +27,9 @@ class Example extends React.Component {
heading: 'Logged in as John Smith (johnsmith@acme.com).',
headingLink: 'Log out',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
onRequestClose={() => {
action('onRequestClose')();
this.setState({ isOpen: false });
}}
/>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/error.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand All @@ -16,9 +18,7 @@ class Example extends React.Component {
'Your browser is currently not supported. Your Salesforce may be degraded.',
headingLink: 'More Information',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
variant="error"
/>
</AlertContainer>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/info.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime
import Icon from '~/components/icon'; // `~` is replaced with design-system-react at runtime
Expand All @@ -15,9 +17,7 @@ class Example extends React.Component {
heading: 'Logged in as John Smith (johnsmith@acme.com).',
headingLink: 'Log out',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
/>
</AlertContainer>
</IconSettings>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/offline.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced with design-system-react at runtime

Expand All @@ -14,9 +16,7 @@ class Example extends React.Component {
heading: 'You are in offline mode.',
headingLink: 'More information',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
variant="offline"
/>
</AlertContainer>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/__examples__/warning.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import { action } from '@storybook/addon-actions';

import Alert from '~/components/alert'; // `~` is replaced with design-system-react at runtime
import AlertContainer from '~/components/alert/container'; // `~` is replaced
import IconSettings from '~/components/icon-settings';
Expand All @@ -14,9 +16,7 @@ class Example extends React.Component {
'Your browser is outdated. Your Salesforce experience may be degraded.',
headingLink: 'More Information',
}}
onClickHeadingLink={() => {
console.log('Link clicked.');
}}
onClickHeadingLink={action('onClickHeadingLink')}
variant="warning"
/>
</AlertContainer>
Expand Down
6 changes: 3 additions & 3 deletions components/alert/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import checkProps from './check-props';
import componentDoc from './component.json';
import { ALERT } from '../../utilities/constants';
import DOMElementFocus from '../../utilities/dom-element-focus';
import EventUtil from '../../utilities/event';

const propTypes = {
/**
Expand Down Expand Up @@ -163,7 +164,6 @@ class Alert extends React.Component {
size: 'x-small',
});

/* eslint-disable no-script-url */
return (
<div
className={classNames(
Expand All @@ -187,8 +187,8 @@ class Alert extends React.Component {
{heading}{' '}
{labels.headingLink ? (
<a
onClick={this.props.onClickHeadingLink}
href="javascript:void(0);"
onClick={EventUtil.trappedHandler(this.props.onClickHeadingLink)}
href="#"
>
{labels.headingLink}
</a>
Expand Down
7 changes: 5 additions & 2 deletions components/app-launcher/link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AppLauncherLink extends React.Component {

// ### Default Props
static defaultProps = {
href: 'javascript:void(0);', // eslint-disable-line no-script-url
href: '#',
};

render() {
Expand All @@ -74,9 +74,12 @@ class AppLauncherLink extends React.Component {

return (
<a
href={this.props.href} // eslint-disable-line no-script-url
href={this.props.href}
className={classNames('slds-truncate', this.props.className)}
onClick={(event) => {
if (this.props.href === '#') {
event.preventDefault();
}
if (this.props.onClick) {
event.preventDefault();
this.props.onClick(event, { href: this.props.href });
Expand Down
7 changes: 5 additions & 2 deletions components/app-launcher/tile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const defaultProps = {
assistiveText: {
dragIconText: 'Reorder',
},
href: 'javascript:void(0);', // eslint-disable-line no-script-url
href: '#',
moreLabel: ' More',
};

Expand Down Expand Up @@ -158,7 +158,10 @@ class AppLauncherTile extends React.Component {
</div>
<div className="slds-app-launcher__tile-body">
<a
href={this.props.href} // eslint-disable-line no-script-url
href={this.props.href}
onClick={(event) =>
this.props.href === '#' && event.preventDefault()
}
>
<Highlighter search={this.props.search}>
{this.props.title}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`DOM snapshots SLDSBreadcrumb 1 Item 1`] = `
className="slds-breadcrumb__item"
>
<a
href="javascript:void(0);"
href="#entity"
>
Parent Entity
</a>
Expand All @@ -40,7 +40,7 @@ exports[`DOM snapshots SLDSBreadcrumb 2 Items 1`] = `
className="slds-breadcrumb__item"
>
<a
href="javascript:void(0);"
href="#entity"
id="parent-entity"
>
Parent Entity
Expand All @@ -50,7 +50,7 @@ exports[`DOM snapshots SLDSBreadcrumb 2 Items 1`] = `
className="slds-breadcrumb__item"
>
<a
href="javascript:void(0);"
href="#record"
>
Parent Record Name
</a>
Expand Down Expand Up @@ -112,7 +112,7 @@ exports[`DOM snapshots SLDSBreadcrumb Base with overflow menu 1`] = `
className="slds-breadcrumb__item"
>
<a
href="javascript:void(0);"
href="#entity"
>
Parent Entity
</a>
Expand All @@ -121,7 +121,7 @@ exports[`DOM snapshots SLDSBreadcrumb Base with overflow menu 1`] = `
className="slds-breadcrumb__item"
>
<a
href="javascript:void(0);"
href="#record"
>
Parent Record Name
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Example extends React.Component {

render() {
const trail = [
<a href="javascript:void(0);">Parent Entity</a>,
<a href="javascript:void(0);">Parent Record Name</a>,
<a href="#entity">Parent Entity</a>,
<a href="#record">Parent Record Name</a>,
];

return (
Expand Down
4 changes: 2 additions & 2 deletions components/breadcrumb/__examples__/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Example extends React.Component {

render() {
const trail = [
<a id="parent-entity" href="javascript:void(0);">
<a id="parent-entity" href="#entity">
Parent Entity
</a>,
<a href="javascript:void(0);">Parent Record Name</a>,
<a href="#record">Parent Record Name</a>,
];

return (
Expand Down
2 changes: 1 addition & 1 deletion components/breadcrumb/__examples__/one-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Example extends React.Component {
static displayName = 'BreadCrumbExample';

render() {
const trail = [<a href="javascript:void(0);">Parent Entity</a>];
const trail = [<a href="#entity">Parent Entity</a>];

return (
<IconSettings iconPath="/assets/icons">
Expand Down
Loading