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

class-observer throws DOMException on line break + tertiary operator #257

Closed
CasiOo opened this issue Dec 9, 2015 · 2 comments
Closed
Labels

Comments

@CasiOo
Copy link
Contributor

CasiOo commented Dec 9, 2015

Line breaks in the class attribute throws a DOMException when combined with using the tertiary operator

Start with a working example:

<div class="${someBoolean ? 'is-true' : 'is-false'}">

</div>

Now insert a line break at the end (valid html according to https://validator.w3.org):

<div class="${someBoolean ? 'is-true' : 'is-false'}
">

</div>

The following exception is then thrown:

Unhandled promise rejection DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided ('is-true
') contains HTML space characters, which are not valid in tokens.
    at Error (native)
    at ClassObserver.setValue (http://localhost:9000/jspm_packages/npm/aurelia-binding@1.0.0-beta.1.0.2/aurelia-binding.js:3764:34)

The funny part is that the line break is part of the class name here https://github.com/aurelia/binding/blob/master/src/class-observer.js#L26

@jdanyow jdanyow added the bug label Dec 12, 2015
@gheoan
Copy link
Contributor

gheoan commented Dec 13, 2015

That HTML is not valid. The error is caused by calling Element.classList.add with whitespace (' ') which should rise an error.

http://www.w3.org/TR/dom/#interface-domtokenlist

The add(tokens…) method must run these steps:

  1. If one of tokens is the empty string, throw a "SyntaxError" exception.
  2. If one of tokens contains any ASCII whitespace, then throw an "InvalidCharacterError" exception.
  3. For each token in tokens, in given order, that is not in tokens, append token to tokens.
  4. Run the update steps.

@jdanyow
Copy link
Contributor

jdanyow commented Dec 13, 2015

@gheoan I think @CasiOo's point is the Aurelia ClassObserver is calling classList.add with unnecessary whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants