fix: make noreferrer warning less zealous

pull/8230/head
Ben McCann 4 years ago
parent eb90a15c29
commit a953b968dd

@ -621,22 +621,19 @@ export default class Element extends Node {
const name_attribute = attribute_map.get('name'); const name_attribute = attribute_map.get('name');
const target_attribute = attribute_map.get('target'); const target_attribute = attribute_map.get('target');
if (target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) { if (component.compile_options.legacy && target_attribute && target_attribute.get_static_value() === '_blank' && href_attribute) {
const href_static_value = href_attribute.get_static_value() ? href_attribute.get_static_value().toLowerCase() : null; const href_static_value = href_attribute.get_static_value() ? href_attribute.get_static_value().toLowerCase() : null;
if (href_static_value === null || href_static_value.match(/^(https?:)?\/\//i)) { if (href_static_value === null || href_static_value.match(/^(https?:)?\/\//i)) {
const rel = attribute_map.get('rel'); const rel = attribute_map.get('rel');
if (rel == null || rel.is_static) { if (rel == null || rel.is_static) {
const rel_values = rel ? rel.get_static_value().split(regex_any_repeated_whitespaces) : []; const rel_values = rel ? rel.get_static_value().split(regex_any_repeated_whitespaces) : [];
const expected_values = ['noreferrer']; if (!rel || (!rel_values.includes('noopener') && !rel_values.includes('noreferrer'))) {
expected_values.forEach(expected_value => {
if (!rel || rel && rel_values.indexOf(expected_value) < 0) {
component.warn(this, { component.warn(this, {
code: `security-anchor-rel-${expected_value}`, code: 'security-anchor-rel-noopener',
message: `Security: Anchor with "target=_blank" should have rel attribute containing the value "${expected_value}"` message: `Security: Anchor with "target=_blank" should have rel attribute containing the value "noopener" or "noreferrer"`
}); });
} }
});
} }
} }
} }

Loading…
Cancel
Save