[BUGFIX beta] Trim whitespace in Ember.String.w() #14611
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently,
Ember.String.w()
has a bit of unexpected behavior when used in the context of theneeds
property of amoduleFor
helper. For instance, one might write the following code:and expect the result of
Ember.String.w()
to be["controller:application", "controller:foo", "controller:bar/index"]
.Surprisingly, the result is
["", "controller:application", "controller:foo", "controller:bar/index", ""]
, which might be fine in and of itself, but blows the call stack ofmoduleFor
:(This PR suggests that
Ember.String.w()
trim whitespace before attempting to split on whitespace. It provides the end user a bit more flexibility with whitespacing of the argument string.I realize that much of the specific pain I encountered could be solved with better whitespacing in the first place, but it does seem a bit odd that
Ember.String.w()
interprets leading and trailing whitespace as elements of the subsequent list to be respected.NB: I tagged this as a BUGFIX, but by all rights it could be a feature request. There's nothing broken per se about the behavior as is, but it does seem a bit surprising, especially when compared to other languages that support collection literals (e.g. ruby's percent strings). That said, I'm fairly novice to both the usage and architecture of ember, so if this isn't a behavior that would be desirable, feel free to disagree.