Skip to content

Commit

Permalink
amp-bind: Fix [class] verify bug (#8938)
Browse files Browse the repository at this point in the history
* fix

* unit tests
  • Loading branch information
William Chou committed Apr 25, 2017
1 parent 6038844 commit 15cdbd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion extensions/amp-bind/0.1/bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,10 @@ export class Bind {
if (Array.isArray(expectedValue)) {
classes = expectedValue;
} else if (typeof expectedValue === 'string') {
classes = expectedValue.split(' ');
const trimmed = expectedValue.trim();
if (trimmed.length > 0) {
classes = trimmed.split(' ');
}
} else {
const err = user().createError(
`${TAG}: "${expectedValue}" is not a valid result for [class].`);
Expand Down
4 changes: 3 additions & 1 deletion extensions/amp-bind/0.1/test/test-bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ describes.realWin('Bind', {

it('should verify class bindings in dev mode', () => {
window.AMP_MODE = {development: true};
createElementWithBinding(`[class]="'foo'" class="foo"`); // No error.
createElementWithBinding(`[class]="'foo'" class="foo"`);
createElementWithBinding(`[class]="'foo'" class=" foo "`);
createElementWithBinding(`[class]="''"`);
createElementWithBinding(`[class]="'bar'" class="qux"`); // Error.
const errorStub = env.sandbox.stub(user(), 'createError');
return onBindReady().then(() => {
Expand Down

0 comments on commit 15cdbd8

Please sign in to comment.