Edit File by line
/home/barbar84/www/wp-inclu.../js/dist
File: blocks.js
* Matches a CSS URL type value
[4000] Fix | Delete
*
[4001] Fix | Delete
* @type {RegExp}
[4002] Fix | Delete
*/
[4003] Fix | Delete
[4004] Fix | Delete
var REGEXP_STYLE_URL_TYPE = /^url\s*\(['"\s]*(.*?)['"\s]*\)$/;
[4005] Fix | Delete
/**
[4006] Fix | Delete
* Boolean attributes are attributes whose presence as being assigned is
[4007] Fix | Delete
* meaningful, even if only empty.
[4008] Fix | Delete
*
[4009] Fix | Delete
* See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes
[4010] Fix | Delete
* Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
[4011] Fix | Delete
*
[4012] Fix | Delete
* Object.keys( Array.from( document.querySelectorAll( '#attributes-1 > tbody > tr' ) )
[4013] Fix | Delete
* .filter( ( tr ) => tr.lastChild.textContent.indexOf( 'Boolean attribute' ) !== -1 )
[4014] Fix | Delete
* .reduce( ( result, tr ) => Object.assign( result, {
[4015] Fix | Delete
* [ tr.firstChild.textContent.trim() ]: true
[4016] Fix | Delete
* } ), {} ) ).sort();
[4017] Fix | Delete
*
[4018] Fix | Delete
* @type {Array}
[4019] Fix | Delete
*/
[4020] Fix | Delete
[4021] Fix | Delete
var BOOLEAN_ATTRIBUTES = ['allowfullscreen', 'allowpaymentrequest', 'allowusermedia', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'default', 'defer', 'disabled', 'download', 'formnovalidate', 'hidden', 'ismap', 'itemscope', 'loop', 'multiple', 'muted', 'nomodule', 'novalidate', 'open', 'playsinline', 'readonly', 'required', 'reversed', 'selected', 'typemustmatch'];
[4022] Fix | Delete
/**
[4023] Fix | Delete
* Enumerated attributes are attributes which must be of a specific value form.
[4024] Fix | Delete
* Like boolean attributes, these are meaningful if specified, even if not of a
[4025] Fix | Delete
* valid enumerated value.
[4026] Fix | Delete
*
[4027] Fix | Delete
* See: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#enumerated-attribute
[4028] Fix | Delete
* Extracted from: https://html.spec.whatwg.org/multipage/indices.html#attributes-3
[4029] Fix | Delete
*
[4030] Fix | Delete
* Object.keys( Array.from( document.querySelectorAll( '#attributes-1 > tbody > tr' ) )
[4031] Fix | Delete
* .filter( ( tr ) => /^("(.+?)";?\s*)+/.test( tr.lastChild.textContent.trim() ) )
[4032] Fix | Delete
* .reduce( ( result, tr ) => Object.assign( result, {
[4033] Fix | Delete
* [ tr.firstChild.textContent.trim() ]: true
[4034] Fix | Delete
* } ), {} ) ).sort();
[4035] Fix | Delete
*
[4036] Fix | Delete
* @type {Array}
[4037] Fix | Delete
*/
[4038] Fix | Delete
[4039] Fix | Delete
var ENUMERATED_ATTRIBUTES = ['autocapitalize', 'autocomplete', 'charset', 'contenteditable', 'crossorigin', 'decoding', 'dir', 'draggable', 'enctype', 'formenctype', 'formmethod', 'http-equiv', 'inputmode', 'kind', 'method', 'preload', 'scope', 'shape', 'spellcheck', 'translate', 'type', 'wrap'];
[4040] Fix | Delete
/**
[4041] Fix | Delete
* Meaningful attributes are those who cannot be safely ignored when omitted in
[4042] Fix | Delete
* one HTML markup string and not another.
[4043] Fix | Delete
*
[4044] Fix | Delete
* @type {Array}
[4045] Fix | Delete
*/
[4046] Fix | Delete
[4047] Fix | Delete
var MEANINGFUL_ATTRIBUTES = [].concat(BOOLEAN_ATTRIBUTES, ENUMERATED_ATTRIBUTES);
[4048] Fix | Delete
/**
[4049] Fix | Delete
* Array of functions which receive a text string on which to apply normalizing
[4050] Fix | Delete
* behavior for consideration in text token equivalence, carefully ordered from
[4051] Fix | Delete
* least-to-most expensive operations.
[4052] Fix | Delete
*
[4053] Fix | Delete
* @type {Array}
[4054] Fix | Delete
*/
[4055] Fix | Delete
[4056] Fix | Delete
var TEXT_NORMALIZATIONS = [external_lodash_["identity"], getTextWithCollapsedWhitespace];
[4057] Fix | Delete
/**
[4058] Fix | Delete
* Regular expression matching a named character reference. In lieu of bundling
[4059] Fix | Delete
* a full set of references, the pattern covers the minimal necessary to test
[4060] Fix | Delete
* positively against the full set.
[4061] Fix | Delete
*
[4062] Fix | Delete
* "The ampersand must be followed by one of the names given in the named
[4063] Fix | Delete
* character references section, using the same case."
[4064] Fix | Delete
*
[4065] Fix | Delete
* Tested aginst "12.5 Named character references":
[4066] Fix | Delete
*
[4067] Fix | Delete
* ```
[4068] Fix | Delete
* const references = Array.from( document.querySelectorAll(
[4069] Fix | Delete
* '#named-character-references-table tr[id^=entity-] td:first-child'
[4070] Fix | Delete
* ) ).map( ( code ) => code.textContent )
[4071] Fix | Delete
* references.every( ( reference ) => /^[\da-z]+$/i.test( reference ) )
[4072] Fix | Delete
* ```
[4073] Fix | Delete
*
[4074] Fix | Delete
* @see https://html.spec.whatwg.org/multipage/syntax.html#character-references
[4075] Fix | Delete
* @see https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references
[4076] Fix | Delete
*
[4077] Fix | Delete
* @type {RegExp}
[4078] Fix | Delete
*/
[4079] Fix | Delete
[4080] Fix | Delete
var REGEXP_NAMED_CHARACTER_REFERENCE = /^[\da-z]+$/i;
[4081] Fix | Delete
/**
[4082] Fix | Delete
* Regular expression matching a decimal character reference.
[4083] Fix | Delete
*
[4084] Fix | Delete
* "The ampersand must be followed by a U+0023 NUMBER SIGN character (#),
[4085] Fix | Delete
* followed by one or more ASCII digits, representing a base-ten integer"
[4086] Fix | Delete
*
[4087] Fix | Delete
* @see https://html.spec.whatwg.org/multipage/syntax.html#character-references
[4088] Fix | Delete
*
[4089] Fix | Delete
* @type {RegExp}
[4090] Fix | Delete
*/
[4091] Fix | Delete
[4092] Fix | Delete
var REGEXP_DECIMAL_CHARACTER_REFERENCE = /^#\d+$/;
[4093] Fix | Delete
/**
[4094] Fix | Delete
* Regular expression matching a hexadecimal character reference.
[4095] Fix | Delete
*
[4096] Fix | Delete
* "The ampersand must be followed by a U+0023 NUMBER SIGN character (#), which
[4097] Fix | Delete
* must be followed by either a U+0078 LATIN SMALL LETTER X character (x) or a
[4098] Fix | Delete
* U+0058 LATIN CAPITAL LETTER X character (X), which must then be followed by
[4099] Fix | Delete
* one or more ASCII hex digits, representing a hexadecimal integer"
[4100] Fix | Delete
*
[4101] Fix | Delete
* @see https://html.spec.whatwg.org/multipage/syntax.html#character-references
[4102] Fix | Delete
*
[4103] Fix | Delete
* @type {RegExp}
[4104] Fix | Delete
*/
[4105] Fix | Delete
[4106] Fix | Delete
var REGEXP_HEXADECIMAL_CHARACTER_REFERENCE = /^#x[\da-f]+$/i;
[4107] Fix | Delete
/**
[4108] Fix | Delete
* Returns true if the given string is a valid character reference segment, or
[4109] Fix | Delete
* false otherwise. The text should be stripped of `&` and `;` demarcations.
[4110] Fix | Delete
*
[4111] Fix | Delete
* @param {string} text Text to test.
[4112] Fix | Delete
*
[4113] Fix | Delete
* @return {boolean} Whether text is valid character reference.
[4114] Fix | Delete
*/
[4115] Fix | Delete
[4116] Fix | Delete
function isValidCharacterReference(text) {
[4117] Fix | Delete
return REGEXP_NAMED_CHARACTER_REFERENCE.test(text) || REGEXP_DECIMAL_CHARACTER_REFERENCE.test(text) || REGEXP_HEXADECIMAL_CHARACTER_REFERENCE.test(text);
[4118] Fix | Delete
}
[4119] Fix | Delete
/**
[4120] Fix | Delete
* Subsitute EntityParser class for `simple-html-tokenizer` which uses the
[4121] Fix | Delete
* implementation of `decodeEntities` from `html-entities`, in order to avoid
[4122] Fix | Delete
* bundling a massive named character reference.
[4123] Fix | Delete
*
[4124] Fix | Delete
* @see https://github.com/tildeio/simple-html-tokenizer/tree/HEAD/src/entity-parser.ts
[4125] Fix | Delete
*/
[4126] Fix | Delete
[4127] Fix | Delete
var validation_DecodeEntityParser = /*#__PURE__*/function () {
[4128] Fix | Delete
function DecodeEntityParser() {
[4129] Fix | Delete
Object(classCallCheck["a" /* default */])(this, DecodeEntityParser);
[4130] Fix | Delete
}
[4131] Fix | Delete
[4132] Fix | Delete
Object(createClass["a" /* default */])(DecodeEntityParser, [{
[4133] Fix | Delete
key: "parse",
[4134] Fix | Delete
[4135] Fix | Delete
/**
[4136] Fix | Delete
* Returns a substitute string for an entity string sequence between `&`
[4137] Fix | Delete
* and `;`, or undefined if no substitution should occur.
[4138] Fix | Delete
*
[4139] Fix | Delete
* @param {string} entity Entity fragment discovered in HTML.
[4140] Fix | Delete
*
[4141] Fix | Delete
* @return {?string} Entity substitute value.
[4142] Fix | Delete
*/
[4143] Fix | Delete
value: function parse(entity) {
[4144] Fix | Delete
if (isValidCharacterReference(entity)) {
[4145] Fix | Delete
return Object(external_wp_htmlEntities_["decodeEntities"])('&' + entity + ';');
[4146] Fix | Delete
}
[4147] Fix | Delete
}
[4148] Fix | Delete
}]);
[4149] Fix | Delete
[4150] Fix | Delete
return DecodeEntityParser;
[4151] Fix | Delete
}();
[4152] Fix | Delete
/**
[4153] Fix | Delete
* Given a specified string, returns an array of strings split by consecutive
[4154] Fix | Delete
* whitespace, ignoring leading or trailing whitespace.
[4155] Fix | Delete
*
[4156] Fix | Delete
* @param {string} text Original text.
[4157] Fix | Delete
*
[4158] Fix | Delete
* @return {string[]} Text pieces split on whitespace.
[4159] Fix | Delete
*/
[4160] Fix | Delete
[4161] Fix | Delete
function getTextPiecesSplitOnWhitespace(text) {
[4162] Fix | Delete
return text.trim().split(REGEXP_WHITESPACE);
[4163] Fix | Delete
}
[4164] Fix | Delete
/**
[4165] Fix | Delete
* Given a specified string, returns a new trimmed string where all consecutive
[4166] Fix | Delete
* whitespace is collapsed to a single space.
[4167] Fix | Delete
*
[4168] Fix | Delete
* @param {string} text Original text.
[4169] Fix | Delete
*
[4170] Fix | Delete
* @return {string} Trimmed text with consecutive whitespace collapsed.
[4171] Fix | Delete
*/
[4172] Fix | Delete
[4173] Fix | Delete
function getTextWithCollapsedWhitespace(text) {
[4174] Fix | Delete
// This is an overly simplified whitespace comparison. The specification is
[4175] Fix | Delete
// more prescriptive of whitespace behavior in inline and block contexts.
[4176] Fix | Delete
//
[4177] Fix | Delete
// See: https://medium.com/@patrickbrosset/when-does-white-space-matter-in-html-b90e8a7cdd33
[4178] Fix | Delete
return getTextPiecesSplitOnWhitespace(text).join(' ');
[4179] Fix | Delete
}
[4180] Fix | Delete
/**
[4181] Fix | Delete
* Returns attribute pairs of the given StartTag token, including only pairs
[4182] Fix | Delete
* where the value is non-empty or the attribute is a boolean attribute, an
[4183] Fix | Delete
* enumerated attribute, or a custom data- attribute.
[4184] Fix | Delete
*
[4185] Fix | Delete
* @see MEANINGFUL_ATTRIBUTES
[4186] Fix | Delete
*
[4187] Fix | Delete
* @param {Object} token StartTag token.
[4188] Fix | Delete
*
[4189] Fix | Delete
* @return {Array[]} Attribute pairs.
[4190] Fix | Delete
*/
[4191] Fix | Delete
[4192] Fix | Delete
function getMeaningfulAttributePairs(token) {
[4193] Fix | Delete
return token.attributes.filter(function (pair) {
[4194] Fix | Delete
var _pair = Object(slicedToArray["a" /* default */])(pair, 2),
[4195] Fix | Delete
key = _pair[0],
[4196] Fix | Delete
value = _pair[1];
[4197] Fix | Delete
[4198] Fix | Delete
return value || key.indexOf('data-') === 0 || Object(external_lodash_["includes"])(MEANINGFUL_ATTRIBUTES, key);
[4199] Fix | Delete
});
[4200] Fix | Delete
}
[4201] Fix | Delete
/**
[4202] Fix | Delete
* Returns true if two text tokens (with `chars` property) are equivalent, or
[4203] Fix | Delete
* false otherwise.
[4204] Fix | Delete
*
[4205] Fix | Delete
* @param {Object} actual Actual token.
[4206] Fix | Delete
* @param {Object} expected Expected token.
[4207] Fix | Delete
* @param {Object} logger Validation logger object.
[4208] Fix | Delete
*
[4209] Fix | Delete
* @return {boolean} Whether two text tokens are equivalent.
[4210] Fix | Delete
*/
[4211] Fix | Delete
[4212] Fix | Delete
function isEquivalentTextTokens(actual, expected) {
[4213] Fix | Delete
var logger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : createLogger();
[4214] Fix | Delete
// This function is intentionally written as syntactically "ugly" as a hot
[4215] Fix | Delete
// path optimization. Text is progressively normalized in order from least-
[4216] Fix | Delete
// to-most operationally expensive, until the earliest point at which text
[4217] Fix | Delete
// can be confidently inferred as being equal.
[4218] Fix | Delete
var actualChars = actual.chars;
[4219] Fix | Delete
var expectedChars = expected.chars;
[4220] Fix | Delete
[4221] Fix | Delete
for (var i = 0; i < TEXT_NORMALIZATIONS.length; i++) {
[4222] Fix | Delete
var normalize = TEXT_NORMALIZATIONS[i];
[4223] Fix | Delete
actualChars = normalize(actualChars);
[4224] Fix | Delete
expectedChars = normalize(expectedChars);
[4225] Fix | Delete
[4226] Fix | Delete
if (actualChars === expectedChars) {
[4227] Fix | Delete
return true;
[4228] Fix | Delete
}
[4229] Fix | Delete
}
[4230] Fix | Delete
[4231] Fix | Delete
logger.warning('Expected text `%s`, saw `%s`.', expected.chars, actual.chars);
[4232] Fix | Delete
return false;
[4233] Fix | Delete
}
[4234] Fix | Delete
/**
[4235] Fix | Delete
* Given a CSS length value, returns a normalized CSS length value for strict equality
[4236] Fix | Delete
* comparison.
[4237] Fix | Delete
*
[4238] Fix | Delete
* @param {string} value CSS length value.
[4239] Fix | Delete
*
[4240] Fix | Delete
* @return {string} Normalized CSS length value.
[4241] Fix | Delete
*/
[4242] Fix | Delete
[4243] Fix | Delete
function getNormalizedLength(value) {
[4244] Fix | Delete
return 0 === parseFloat(value) ? '0' : value;
[4245] Fix | Delete
}
[4246] Fix | Delete
/**
[4247] Fix | Delete
* Given a style value, returns a normalized style value for strict equality
[4248] Fix | Delete
* comparison.
[4249] Fix | Delete
*
[4250] Fix | Delete
* @param {string} value Style value.
[4251] Fix | Delete
*
[4252] Fix | Delete
* @return {string} Normalized style value.
[4253] Fix | Delete
*/
[4254] Fix | Delete
[4255] Fix | Delete
function getNormalizedStyleValue(value) {
[4256] Fix | Delete
var textPieces = getTextPiecesSplitOnWhitespace(value);
[4257] Fix | Delete
var normalizedPieces = textPieces.map(getNormalizedLength);
[4258] Fix | Delete
var result = normalizedPieces.join(' ');
[4259] Fix | Delete
return result // Normalize URL type to omit whitespace or quotes
[4260] Fix | Delete
.replace(REGEXP_STYLE_URL_TYPE, 'url($1)');
[4261] Fix | Delete
}
[4262] Fix | Delete
/**
[4263] Fix | Delete
* Given a style attribute string, returns an object of style properties.
[4264] Fix | Delete
*
[4265] Fix | Delete
* @param {string} text Style attribute.
[4266] Fix | Delete
*
[4267] Fix | Delete
* @return {Object} Style properties.
[4268] Fix | Delete
*/
[4269] Fix | Delete
[4270] Fix | Delete
function getStyleProperties(text) {
[4271] Fix | Delete
var pairs = text // Trim ending semicolon (avoid including in split)
[4272] Fix | Delete
.replace(/;?\s*$/, '') // Split on property assignment
[4273] Fix | Delete
.split(';') // For each property assignment...
[4274] Fix | Delete
.map(function (style) {
[4275] Fix | Delete
// ...split further into key-value pairs
[4276] Fix | Delete
var _style$split = style.split(':'),
[4277] Fix | Delete
_style$split2 = Object(toArray["a" /* default */])(_style$split),
[4278] Fix | Delete
key = _style$split2[0],
[4279] Fix | Delete
valueParts = _style$split2.slice(1);
[4280] Fix | Delete
[4281] Fix | Delete
var value = valueParts.join(':');
[4282] Fix | Delete
return [key.trim(), getNormalizedStyleValue(value.trim())];
[4283] Fix | Delete
});
[4284] Fix | Delete
return Object(external_lodash_["fromPairs"])(pairs);
[4285] Fix | Delete
}
[4286] Fix | Delete
/**
[4287] Fix | Delete
* Attribute-specific equality handlers
[4288] Fix | Delete
*
[4289] Fix | Delete
* @type {Object}
[4290] Fix | Delete
*/
[4291] Fix | Delete
[4292] Fix | Delete
var isEqualAttributesOfName = validation_objectSpread({
[4293] Fix | Delete
class: function _class(actual, expected) {
[4294] Fix | Delete
// Class matches if members are the same, even if out of order or
[4295] Fix | Delete
// superfluous whitespace between.
[4296] Fix | Delete
return !external_lodash_["xor"].apply(void 0, Object(toConsumableArray["a" /* default */])([actual, expected].map(getTextPiecesSplitOnWhitespace))).length;
[4297] Fix | Delete
},
[4298] Fix | Delete
style: function style(actual, expected) {
[4299] Fix | Delete
return external_lodash_["isEqual"].apply(void 0, Object(toConsumableArray["a" /* default */])([actual, expected].map(getStyleProperties)));
[4300] Fix | Delete
}
[4301] Fix | Delete
}, Object(external_lodash_["fromPairs"])(BOOLEAN_ATTRIBUTES.map(function (attribute) {
[4302] Fix | Delete
return [attribute, external_lodash_["stubTrue"]];
[4303] Fix | Delete
})));
[4304] Fix | Delete
/**
[4305] Fix | Delete
* Given two sets of attribute tuples, returns true if the attribute sets are
[4306] Fix | Delete
* equivalent.
[4307] Fix | Delete
*
[4308] Fix | Delete
* @param {Array[]} actual Actual attributes tuples.
[4309] Fix | Delete
* @param {Array[]} expected Expected attributes tuples.
[4310] Fix | Delete
* @param {Object} logger Validation logger object.
[4311] Fix | Delete
*
[4312] Fix | Delete
* @return {boolean} Whether attributes are equivalent.
[4313] Fix | Delete
*/
[4314] Fix | Delete
[4315] Fix | Delete
function isEqualTagAttributePairs(actual, expected) {
[4316] Fix | Delete
var logger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : createLogger();
[4317] Fix | Delete
[4318] Fix | Delete
// Attributes is tokenized as tuples. Their lengths should match. This also
[4319] Fix | Delete
// avoids us needing to check both attributes sets, since if A has any keys
[4320] Fix | Delete
// which do not exist in B, we know the sets to be different.
[4321] Fix | Delete
if (actual.length !== expected.length) {
[4322] Fix | Delete
logger.warning('Expected attributes %o, instead saw %o.', expected, actual);
[4323] Fix | Delete
return false;
[4324] Fix | Delete
} // Attributes are not guaranteed to occur in the same order. For validating
[4325] Fix | Delete
// actual attributes, first convert the set of expected attribute values to
[4326] Fix | Delete
// an object, for lookup by key.
[4327] Fix | Delete
[4328] Fix | Delete
[4329] Fix | Delete
var expectedAttributes = {};
[4330] Fix | Delete
[4331] Fix | Delete
for (var i = 0; i < expected.length; i++) {
[4332] Fix | Delete
expectedAttributes[expected[i][0].toLowerCase()] = expected[i][1];
[4333] Fix | Delete
}
[4334] Fix | Delete
[4335] Fix | Delete
for (var _i = 0; _i < actual.length; _i++) {
[4336] Fix | Delete
var _actual$_i = Object(slicedToArray["a" /* default */])(actual[_i], 2),
[4337] Fix | Delete
name = _actual$_i[0],
[4338] Fix | Delete
actualValue = _actual$_i[1];
[4339] Fix | Delete
[4340] Fix | Delete
var nameLower = name.toLowerCase(); // As noted above, if missing member in B, assume different
[4341] Fix | Delete
[4342] Fix | Delete
if (!expectedAttributes.hasOwnProperty(nameLower)) {
[4343] Fix | Delete
logger.warning('Encountered unexpected attribute `%s`.', name);
[4344] Fix | Delete
return false;
[4345] Fix | Delete
}
[4346] Fix | Delete
[4347] Fix | Delete
var expectedValue = expectedAttributes[nameLower];
[4348] Fix | Delete
var isEqualAttributes = isEqualAttributesOfName[nameLower];
[4349] Fix | Delete
[4350] Fix | Delete
if (isEqualAttributes) {
[4351] Fix | Delete
// Defer custom attribute equality handling
[4352] Fix | Delete
if (!isEqualAttributes(actualValue, expectedValue)) {
[4353] Fix | Delete
logger.warning('Expected attribute `%s` of value `%s`, saw `%s`.', name, expectedValue, actualValue);
[4354] Fix | Delete
return false;
[4355] Fix | Delete
}
[4356] Fix | Delete
} else if (actualValue !== expectedValue) {
[4357] Fix | Delete
// Otherwise strict inequality should bail
[4358] Fix | Delete
logger.warning('Expected attribute `%s` of value `%s`, saw `%s`.', name, expectedValue, actualValue);
[4359] Fix | Delete
return false;
[4360] Fix | Delete
}
[4361] Fix | Delete
}
[4362] Fix | Delete
[4363] Fix | Delete
return true;
[4364] Fix | Delete
}
[4365] Fix | Delete
/**
[4366] Fix | Delete
* Token-type-specific equality handlers
[4367] Fix | Delete
*
[4368] Fix | Delete
* @type {Object}
[4369] Fix | Delete
*/
[4370] Fix | Delete
[4371] Fix | Delete
var isEqualTokensOfType = {
[4372] Fix | Delete
StartTag: function StartTag(actual, expected) {
[4373] Fix | Delete
var logger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : createLogger();
[4374] Fix | Delete
[4375] Fix | Delete
if (actual.tagName !== expected.tagName && // Optimization: Use short-circuit evaluation to defer case-
[4376] Fix | Delete
// insensitive check on the assumption that the majority case will
[4377] Fix | Delete
// have exactly equal tag names.
[4378] Fix | Delete
actual.tagName.toLowerCase() !== expected.tagName.toLowerCase()) {
[4379] Fix | Delete
logger.warning('Expected tag name `%s`, instead saw `%s`.', expected.tagName, actual.tagName);
[4380] Fix | Delete
return false;
[4381] Fix | Delete
}
[4382] Fix | Delete
[4383] Fix | Delete
return isEqualTagAttributePairs.apply(void 0, Object(toConsumableArray["a" /* default */])([actual, expected].map(getMeaningfulAttributePairs)).concat([logger]));
[4384] Fix | Delete
},
[4385] Fix | Delete
Chars: isEquivalentTextTokens,
[4386] Fix | Delete
Comment: isEquivalentTextTokens
[4387] Fix | Delete
};
[4388] Fix | Delete
/**
[4389] Fix | Delete
* Given an array of tokens, returns the first token which is not purely
[4390] Fix | Delete
* whitespace.
[4391] Fix | Delete
*
[4392] Fix | Delete
* Mutates the tokens array.
[4393] Fix | Delete
*
[4394] Fix | Delete
* @param {Object[]} tokens Set of tokens to search.
[4395] Fix | Delete
*
[4396] Fix | Delete
* @return {Object} Next non-whitespace token.
[4397] Fix | Delete
*/
[4398] Fix | Delete
[4399] Fix | Delete
function getNextNonWhitespaceToken(tokens) {
[4400] Fix | Delete
var token;
[4401] Fix | Delete
[4402] Fix | Delete
while (token = tokens.shift()) {
[4403] Fix | Delete
if (token.type !== 'Chars') {
[4404] Fix | Delete
return token;
[4405] Fix | Delete
}
[4406] Fix | Delete
[4407] Fix | Delete
if (!REGEXP_ONLY_WHITESPACE.test(token.chars)) {
[4408] Fix | Delete
return token;
[4409] Fix | Delete
}
[4410] Fix | Delete
}
[4411] Fix | Delete
}
[4412] Fix | Delete
/**
[4413] Fix | Delete
* Tokenize an HTML string, gracefully handling any errors thrown during
[4414] Fix | Delete
* underlying tokenization.
[4415] Fix | Delete
*
[4416] Fix | Delete
* @param {string} html HTML string to tokenize.
[4417] Fix | Delete
* @param {Object} logger Validation logger object.
[4418] Fix | Delete
*
[4419] Fix | Delete
* @return {Object[]|null} Array of valid tokenized HTML elements, or null on error
[4420] Fix | Delete
*/
[4421] Fix | Delete
[4422] Fix | Delete
function getHTMLTokens(html) {
[4423] Fix | Delete
var logger = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createLogger();
[4424] Fix | Delete
[4425] Fix | Delete
try {
[4426] Fix | Delete
return new Tokenizer(new validation_DecodeEntityParser()).tokenize(html);
[4427] Fix | Delete
} catch (e) {
[4428] Fix | Delete
logger.warning('Malformed HTML detected: %s', html);
[4429] Fix | Delete
}
[4430] Fix | Delete
[4431] Fix | Delete
return null;
[4432] Fix | Delete
}
[4433] Fix | Delete
/**
[4434] Fix | Delete
* Returns true if the next HTML token closes the current token.
[4435] Fix | Delete
*
[4436] Fix | Delete
* @param {Object} currentToken Current token to compare with.
[4437] Fix | Delete
* @param {Object|undefined} nextToken Next token to compare against.
[4438] Fix | Delete
*
[4439] Fix | Delete
* @return {boolean} true if `nextToken` closes `currentToken`, false otherwise
[4440] Fix | Delete
*/
[4441] Fix | Delete
[4442] Fix | Delete
[4443] Fix | Delete
function isClosedByToken(currentToken, nextToken) {
[4444] Fix | Delete
// Ensure this is a self closed token
[4445] Fix | Delete
if (!currentToken.selfClosing) {
[4446] Fix | Delete
return false;
[4447] Fix | Delete
} // Check token names and determine if nextToken is the closing tag for currentToken
[4448] Fix | Delete
[4449] Fix | Delete
[4450] Fix | Delete
if (nextToken && nextToken.tagName === currentToken.tagName && nextToken.type === 'EndTag') {
[4451] Fix | Delete
return true;
[4452] Fix | Delete
}
[4453] Fix | Delete
[4454] Fix | Delete
return false;
[4455] Fix | Delete
}
[4456] Fix | Delete
/**
[4457] Fix | Delete
* Returns true if the given HTML strings are effectively equivalent, or
[4458] Fix | Delete
* false otherwise. Invalid HTML is not considered equivalent, even if the
[4459] Fix | Delete
* strings directly match.
[4460] Fix | Delete
*
[4461] Fix | Delete
* @param {string} actual Actual HTML string.
[4462] Fix | Delete
* @param {string} expected Expected HTML string.
[4463] Fix | Delete
* @param {Object} logger Validation logger object.
[4464] Fix | Delete
*
[4465] Fix | Delete
* @return {boolean} Whether HTML strings are equivalent.
[4466] Fix | Delete
*/
[4467] Fix | Delete
[4468] Fix | Delete
function isEquivalentHTML(actual, expected) {
[4469] Fix | Delete
var logger = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : createLogger();
[4470] Fix | Delete
[4471] Fix | Delete
// Short-circuit if markup is identical.
[4472] Fix | Delete
if (actual === expected) {
[4473] Fix | Delete
return true;
[4474] Fix | Delete
} // Tokenize input content and reserialized save content
[4475] Fix | Delete
[4476] Fix | Delete
[4477] Fix | Delete
var _map = [actual, expected].map(function (html) {
[4478] Fix | Delete
return getHTMLTokens(html, logger);
[4479] Fix | Delete
}),
[4480] Fix | Delete
_map2 = Object(slicedToArray["a" /* default */])(_map, 2),
[4481] Fix | Delete
actualTokens = _map2[0],
[4482] Fix | Delete
expectedTokens = _map2[1]; // If either is malformed then stop comparing - the strings are not equivalent
[4483] Fix | Delete
[4484] Fix | Delete
[4485] Fix | Delete
if (!actualTokens || !expectedTokens) {
[4486] Fix | Delete
return false;
[4487] Fix | Delete
}
[4488] Fix | Delete
[4489] Fix | Delete
var actualToken, expectedToken;
[4490] Fix | Delete
[4491] Fix | Delete
while (actualToken = getNextNonWhitespaceToken(actualTokens)) {
[4492] Fix | Delete
expectedToken = getNextNonWhitespaceToken(expectedTokens); // Inequal if exhausted all expected tokens
[4493] Fix | Delete
[4494] Fix | Delete
if (!expectedToken) {
[4495] Fix | Delete
logger.warning('Expected end of content, instead saw %o.', actualToken);
[4496] Fix | Delete
return false;
[4497] Fix | Delete
} // Inequal if next non-whitespace token of each set are not same type
[4498] Fix | Delete
[4499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function