Skip to content

Commit 973944f

Browse files
committed
fix(uiSref): accepts multi-line attribute values
Closes #503
1 parent 772b458 commit 973944f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/stateDirectives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function parseStateRef(ref) {
2-
var parsed = ref.match(/^([^(]+?)\s*(\((.*)\))?$/);
2+
var parsed = ref.replace(/\n/g, " ").match(/^([^(]+?)\s*(\((.*)\))?$/);
33
if (!parsed || parsed.length !== 4) throw new Error("Invalid state ref '" + ref + "'");
44
return { state: parsed[1], paramExpr: parsed[3] || null };
55
}

test/stateDirectivesSpec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ describe('uiStateRef', function() {
9090
expect(el.attr('href')).toBe('#/contacts/6');
9191
});
9292

93+
it('should allow multi-line attribute values', inject(function($compile, $rootScope) {
94+
el = angular.element("<a ui-sref=\"contacts.item.detail({\n\tid: $index\n})\">Details</a>");
95+
$rootScope.$index = 3;
96+
$rootScope.$apply();
97+
98+
$compile(el)($rootScope);
99+
$rootScope.$digest();
100+
expect(el.attr('href')).toBe('#/contacts/3');
101+
}));
102+
93103
it('should transition states when left-clicked', inject(function($state, $stateParams, $document, $q) {
94104
expect($state.$current.name).toEqual('');
95105

0 commit comments

Comments
 (0)