Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes to the templates component of the validator. #1145

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions validator/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,11 @@ ParsedTagSpec.prototype.getSpec = function() {
return this.spec_;
};

/**
* Returns true if |value| contains a mustache unescaped template syntax.
* @param {!string} value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string is already !.

* @return {boolean}
*/
ParsedTagSpec.prototype.valueHasUnescapedTemplateSyntax = function(value) {
// Mustache (https://mustache.github.io/mustache.5.html), our template
// system, supports {{{unescaped}}} or {{{&unescaped}}} and there can
Expand All @@ -1294,13 +1299,18 @@ ParsedTagSpec.prototype.valueHasUnescapedTemplateSyntax = function(value) {
return unescapedOpenTag.test(value);
};

/**
* Returns true if |value| contains a mustache partials template syntax.
* @param {!string} value
* @return {boolean}
*/
ParsedTagSpec.prototype.valueHasPartialsTemplateSyntax = function(value) {
// Mustache (https://mustache.github.io/mustache.5.html), our template
// system, supports 'partials' which include other Mustache templates
// in the format of {{>partial}} and there can be whitespace after the {{.
// We disallow partials in attribute values.
const unescapedOpenTag = new RegExp('{{\\s*>', 'g');
return unescapedOpenTag.test(value);
const partialsTag = new RegExp('{{\\s*>', 'g');
return partialsTag.test(value);
};

/**
Expand Down Expand Up @@ -1463,17 +1473,19 @@ ParsedTagSpec.prototype.validateAttributes = function(
}
return;
}
if (parsedSpec.valueHasUnescapedTemplateSyntax(encounteredAttrValue)) {
if (this.valueHasUnescapedTemplateSyntax(encounteredAttrValue)) {
context.addError(
amp.validator.ValidationError.Code.UNESCAPED_TEMPLATE_IN_ATTR_VALUE,
encounteredAttrName + '=' + encounteredAttrValue,
this.templateSpecUrl_, resultForAttempt);
return;
}
if (parsedSpec.valueHasPartialsTemplateSyntax(encounteredAttrValue)) {
if (this.valueHasPartialsTemplateSyntax(encounteredAttrValue)) {
context.addError(
amp.validator.ValidationError.Code.TEMPLATE_PARTIAL_IN_ATTR_VALUE,
encounteredAttrName + '=' + encounteredAttrValue,
this.templateSpecUrl_, resultForAttempt);
return;
}

if (parsedSpec.getSpec().deprecation !== null) {
Expand Down