Skip to content

Commit

Permalink
Merge pull request #1289 from fwolfst/1288-let_link_to_blank_find_lin…
Browse files Browse the repository at this point in the history
…k_to_if_and_unless

[Fix #1288] Let LinkToBlank find violations in link_to_if and link_to_unless
  • Loading branch information
koic authored Jun 19, 2024
2 parents bb1d373 + e8d60f3 commit d99bbe1
Show file tree
Hide file tree
Showing 3 changed files with 396 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1288](https://github.com/rubocop/rubocop-rails/issues/1288): Let `Rails/LinkToBlank` look into `link_to_if` and `link_to_unless`, too. ([@fwolfst][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rails/link_to_blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module RuboCop
module Cop
module Rails
# Checks for calls to `link_to` that contain a
# Checks for calls to `link_to`, `link_to_if`, and `link_to_unless` methods that contain a
# `target: '_blank'` but no `rel: 'noopener'`. This can be a security
# risk as the loaded page will have control over the previous page
# and could change its location for phishing purposes.
Expand All @@ -24,7 +24,7 @@ class LinkToBlank < Base
extend AutoCorrector

MSG = 'Specify a `:rel` option containing noopener.'
RESTRICT_ON_SEND = %i[link_to].freeze
RESTRICT_ON_SEND = %i[link_to link_to_if link_to_unless].freeze

def_node_matcher :blank_target?, <<~PATTERN
(pair {(sym :target) (str "target")} {(str "_blank") (sym :_blank)})
Expand Down
Loading

0 comments on commit d99bbe1

Please sign in to comment.