import __unstableEscapeGreaterThan from './escape-greater'; /** * Regular expression matching invalid attribute names. * * "Attribute names must consist of one or more characters other than controls, * U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=), * and noncharacters." * * @see https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 */ const REGEXP_INVALID_ATTRIBUTE_NAME: RegExp = /[\u007F-\u009F "'>/="\uFDD0-\uFDEF]/; /** * Returns a string with ampersands escaped. Note that this is an imperfect * implementation, where only ampersands which do not appear as a pattern of * named, decimal, or hexadecimal character references are escaped. Invalid * named references (i.e. ambiguous ampersand) are still permitted. * * @see https://w3c.github.io/html/syntax.html#character-references * @see https://w3c.github.io/html/syntax.html#ambiguous-ampersand * @see https://w3c.github.io/html/syntax.html#named-character-references * * @param value Original string. * * @return Escaped string. */ export function escapeAmpersand( value: string ): string { return value.replace( /&(?!([a-z0-9]+|#[0-9]+|#x[a-f0-9]+);)/gi, '&' ); } /** * Returns a string with quotation marks replaced. * * @param value Original string. * * @return Escaped string. */ export function escapeQuotationMark( value: string ): string { return value.replace( /"/g, '"' ); } /** * Returns a string with less-than sign replaced. * * @param value Original string. * * @return Escaped string. */ export function escapeLessThan( value: string ): string { return value.replace( /