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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions blocks/rich-text/format-toolbar/index.js
Expand Up @@ -112,7 +112,11 @@ 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' : '' } } );
this.props.onChange( { link: {
value: this.props.formats.link.value,
target: opensInNewWindow ? '_blank' : null,
rel: opensInNewWindow ? 'noreferrer noopener' : null,
} } );
}
}

Expand All @@ -133,7 +137,11 @@ 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' : '' } } );
this.props.onChange( { link: {
value: this.state.newLinkValue,
target: this.state.opensInNewWindow ? '_blank' : null,
rel: this.state.opensInNewWindow ? 'noreferrer noopener' : null,
} } );
if ( this.state.isAddingLink ) {
this.props.speak( __( 'Link added.' ), 'assertive' );
}
Expand Down
3 changes: 2 additions & 1 deletion blocks/rich-text/index.js
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