Skip to content
This repository has been archived by the owner. It is now read-only.

fix(ngClass): do not break on invalid values #16699

Closed
wants to merge 1 commit into from

Conversation

gkalpak
Copy link
Member

@gkalpak gkalpak commented Sep 19, 2018

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix.

What is the current behavior? (You can also link to an open issue here)
When an ngClass expression evaluates to something that is not a string, array or object (and is truthy), an error will be thrown while trying to call .split() on a non-string value. This error is not very helpful for the user to identify the root cause of the problem.
See #16697.

What is the new behavior (if this is a feature change)?
Such values are converted to string.

Does this PR introduce a breaking change?
No.

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:
Fixes #16697.

Previously, when an `ngClass` expression evaluated to something that was
not a string, array or object (and was truthy), an error would be thrown
while trying to call `.split()` on a non-string value. This error was
not very helpful for the user to identify the root cause of the problem.

This commit fixes it by ensuring such values are converted to string.

Fixes angular#16697
@gkalpak
Copy link
Member Author

@gkalpak gkalpak commented Sep 19, 2018

Or maybe it is better to just throw a more informative error instead.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

I think this is reasonable.

@petebacondarwin petebacondarwin removed this from the 1.7.x milestone Sep 19, 2018
@petebacondarwin petebacondarwin added this to the 1.7.x - won't fix milestone Sep 19, 2018
gkalpak added a commit that referenced this issue Sep 20, 2018
Previously, when an `ngClass` expression evaluated to something that was
not a string, array or object (and was truthy), an error would be thrown
while trying to call `.split()` on a non-string value. This error was
not very helpful for the user to identify the root cause of the problem.

This commit fixes it by ensuring such values are converted to string.

Fixes #16697

Closes #16699
@gkalpak gkalpak deleted the fix-ngClass-non-string branch Oct 11, 2018
@Splaktar
Copy link
Member

@Splaktar Splaktar commented Nov 29, 2018

This milestone seems to be inaccurate since this went into 1.7.5. 😇

@gkalpak gkalpak removed this from the 1.7.x - won't fix milestone Nov 29, 2018
@gkalpak gkalpak added this to the 1.7.x milestone Nov 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants