moved array of characters to own constant

pull/7663/head
Mathias Picker 4 years ago
parent 166978bdf9
commit 523c799402

@ -11,6 +11,7 @@ import { closing_tag_omitted, decode_character_references } from '../utils/html'
// characters equivalent to using \s in regex // characters equivalent to using \s in regex
const whitespace_characters = ['\r', '\n', '\t', '\f', '\v', ' ', '\u00a0', '\u1680', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000', '\ufeff']; const whitespace_characters = ['\r', '\n', '\t', '\f', '\v', ' ', '\u00a0', '\u1680', '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', '\u2007', '\u2008', '\u2009', '\u200a', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000', '\ufeff'];
const invalid_attribute_characters = [...whitespace_characters, '/', '"', '\'', '=', '<', '>', '`'];
// eslint-disable-next-line no-useless-escape // eslint-disable-next-line no-useless-escape
const valid_tag_name = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/; const valid_tag_name = /^\!?[a-zA-Z]{1,}:?[a-zA-Z0-9\-]*/;
@ -367,7 +368,6 @@ function read_attribute(parser: Parser, unique_names: Set<string>) {
parser.error(parser_errors.unexpected_token('='), parser.index); parser.error(parser_errors.unexpected_token('='), parser.index);
} }
if (type) { if (type) {
const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|');
@ -473,8 +473,10 @@ function read_attribute_value(parser: Parser) {
let value; let value;
try { try {
const characters = quote_mark ? [quote_mark] : [...whitespace_characters, '/>', '"', '\'', '=', '<', '>', '`']; value = read_sequence(parser, () => {
value = read_sequence(parser, () => characters.some(c => parser.match(c))); if (quote_mark) return parser.match(quote_mark);
return invalid_attribute_characters.some(c => parser.match(c));
});
} catch (error) { } catch (error) {
if (error.code === 'parse-error') { if (error.code === 'parse-error') {
// if the attribute value didn't close + self-closing tag // if the attribute value didn't close + self-closing tag

Loading…
Cancel
Save