Skip to content
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

Links: Add ref="noreferrer noopener" for target="_blank" links #6316

Merged
merged 2 commits into from
Apr 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions blocks/rich-text/format-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ class FormatToolbar extends Component {
setLinkTarget( opensInNewWindow ) {
this.setState( { opensInNewWindow } );
if ( this.props.formats.link ) {
this.props.onChange( { link: { value: this.props.formats.link.value, target: opensInNewWindow ? '_blank' : '' } } );
const extraParams = opensInNewWindow ? { target: '_blank', rel: 'noreferrer noopener' } : {};
this.props.onChange( { link: { value: this.props.formats.link.value, ...extraParams } } );
}
}

Expand All @@ -133,7 +134,8 @@ class FormatToolbar extends Component {
submitLink( event ) {
event.preventDefault();
this.setState( { isEditingLink: false, isAddingLink: false, newLinkValue: '' } );
this.props.onChange( { link: { value: this.state.newLinkValue, target: this.state.opensInNewWindow ? '_blank' : '' } } );
const extraParams = this.state.opensInNewWindow ? { target: '_blank', rel: 'noreferrer noopener' } : {};
this.props.onChange( { link: { value: this.state.newLinkValue, ...extraParams } } );
if ( this.state.isAddingLink ) {
this.props.speak( __( 'Link added.' ), 'assertive' );
}
Expand Down
3 changes: 2 additions & 1 deletion blocks/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ export class RichText extends Component {
if ( ! anchor ) {
this.removeFormat( 'link' );
}
this.applyFormat( 'link', { href: formatValue.value, target: formatValue.target }, anchor );
const { value: href, ...params } = formatValue;
this.applyFormat( 'link', { href, ...params }, anchor );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we could avoid some friction if we named the attribute href instead of value, but eh.

} else {
this.editor.execCommand( 'Unlink' );
}
Expand Down