Skip to content

Commit a953b96

Browse files
committed
fix: make noreferrer warning less zealous
1 parent eb90a15 commit a953b96

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/compiler/compile/nodes/Element.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,22 +621,19 @@ export default class Element extends Node {
621621
const name_attribute = attribute_map.get('name');
622622
const target_attribute = attribute_map.get('target');
623623

624-
if (target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) {
624+
if (component.compile_options.legacy && target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) {
625625
const href_static_value = href_attribute.get_static_value() ? href_attribute.get_static_value().toLowerCase() : null;
626626

627627
if (href_static_value === null || href_static_value.match(/^(https?:)?\/\//i)) {
628628
const rel = attribute_map.get('rel');
629629
if (rel == null || rel.is_static) {
630630
const rel_values = rel ? rel.get_static_value().split(regex_any_repeated_whitespaces) : [];
631-
const expected_values = ['noreferrer'];
632-
expected_values.forEach(expected_value => {
633-
if (!rel || rel && rel_values.indexOf(expected_value) < 0) {
631+
if (!rel || (!rel_values.includes('noopener') && !rel_values.includes('noreferrer'))) {
634632
component.warn(this, {
635-
code: `security-anchor-rel-${expected_value}`,
636-
message: `Security: Anchor with "target=_blank" should have rel attribute containing the value "${expected_value}"`
633+
code: 'security-anchor-rel-noopener',
634+
message: `Security: Anchor with "target=_blank" should have rel attribute containing the value "noopener" or "noreferrer"`
637635
});
638-
}
639-
});
636+
}
640637
}
641638
}
642639
}

0 commit comments

Comments
 (0)