Skip to content
This repository has been archived by the owner on Apr 12, 2024. 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 commented Sep 19, 2018

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

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I think this is reasonable.

@gkalpak gkalpak closed this in 26ddc5f Sep 20, 2018
gkalpak added a commit that referenced this pull request 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 October 11, 2018 16:37
@Splaktar
Copy link
Member

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

@gkalpak gkalpak modified the milestones: 1.7.x - won't fix, 1.7.x 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.

Error classString.split is not a function
4 participants