Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit fa02e4e

Browse files
ThomasBurlesonmmalerba
authored andcommitted
fix(layout): trim attribute values before use (#10462)
Angular 1.6, which contains the 'don't trim white-space in attributes' commit (angular/angular.js@97bbf86), fixes #10426.
1 parent eecc541 commit fa02e4e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/core/services/layout/layout.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
var value = validateAttributeValue(className, newValue || "");
361361
if ( angular.isDefined(value) ) {
362362
if (lastClass) element.removeClass(lastClass);
363-
lastClass = !value ? className : className + "-" + value.replace(WHITESPACE, "-");
363+
lastClass = !value ? className : className + "-" + value.trim().replace(WHITESPACE, "-");
364364
element.addClass(lastClass);
365365
}
366366
};
@@ -407,7 +407,7 @@
407407
* fallback value
408408
*/
409409
function validateAttributeValue(className, value, updateFn) {
410-
var origValue = value;
410+
var origValue;
411411

412412
if (!needsInterpolation(value)) {
413413
switch (className.replace(SUFFIXES,"")) {
@@ -452,7 +452,7 @@
452452
}
453453
}
454454

455-
return value;
455+
return value ? value.trim() : "";
456456
}
457457

458458
/**
@@ -479,7 +479,7 @@
479479

480480
function getNormalizedAttrValue(className, attrs, defaultVal) {
481481
var normalizedAttr = attrs.$normalize(className);
482-
return attrs[normalizedAttr] ? attrs[normalizedAttr].replace(WHITESPACE, "-") : defaultVal || null;
482+
return attrs[normalizedAttr] ? attrs[normalizedAttr].trim().replace(WHITESPACE, "-") : defaultVal || null;
483483
}
484484

485485
function findIn(item, list, replaceWith) {

src/core/services/layout/layout.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ describe("Layout API ", function() {
132132
expect(element.hasClass('flex-gt-sm')).toBeTruthy();
133133
});
134134

135+
it('should support untrimmed attribute values with spaces', inject(function($rootScope, $compile) {
136+
var scope = pageScope;
137+
var element = angular.element($compile('<div flex-gt-xs="50 "></div>')(scope));
138+
139+
expect(element.hasClass('flex-gt-xs-50')).toBe(true);
140+
}));
141+
135142
it('should observe the attribute value and update the layout class(es)', inject(function($rootScope, $compile) {
136143
var scope = pageScope;
137144
var element = angular.element($compile('<div flex-gt-md="{{size}}"></div>')(scope));

0 commit comments

Comments
 (0)