Skip to content

Commit e0710c4

Browse files
pkozlowski-opensourcemhevery
authored andcommitted
fix(PropertyBindingParser): detect bindings using full attribute name
Fixes angular#1001 Closes angular#1004
1 parent 476386f commit e0710c4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

modules/angular2/src/core/compiler/pipeline/property_binding_parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {CompileControl} from './compile_control';
1717
// Group 7 = "#"
1818
// Group 8 = identifier after "#"
1919
var BIND_NAME_REGEXP = RegExpWrapper.create(
20-
'^(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+)');
20+
'^(?:(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+))$');
2121

2222
/**
2323
* Parses the property bindings on a single element.

modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ export function main() {
2525
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
2626
});
2727

28+
it('should detect [] syntax only if an attribute name starts and ends with []', () => {
29+
expect(createPipeline().process(el('<div z[a]="b"></div>'))[0].propertyBindings).toBe(null);
30+
expect(createPipeline().process(el('<div [a]v="b"></div>'))[0].propertyBindings).toBe(null);
31+
});
32+
2833
it('should detect bind- syntax', () => {
2934
var results = createPipeline().process(el('<div bind-a="b"></div>'));
3035
expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b');
3136
});
3237

38+
it('should detect bind- syntax only if an attribute name starts with bind', () => {
39+
expect(createPipeline().process(el('<div _bind-a="b"></div>'))[0].propertyBindings).toBe(null);
40+
});
41+
3342
it('should detect interpolation syntax', () => {
3443
// Note: we don't test all corner cases of interpolation as we assume shared functionality between text interpolation
3544
// and attribute interpolation.
@@ -62,6 +71,11 @@ export function main() {
6271
expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george');
6372
});
6473

74+
it('should detect variable bindings only if an attribute name starts with #', () => {
75+
var results = createPipeline().process(el('<p b#george></p>'));
76+
expect(results[0].variableBindings).toBe(null);
77+
});
78+
6579
it('should detect () syntax', () => {
6680
var results = createPipeline().process(el('<div (click)="b()"></div>'));
6781
expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('b()');
@@ -70,6 +84,11 @@ export function main() {
7084
expect(MapWrapper.get(results[0].eventBindings, 'click[]').source).toEqual('b()');
7185
});
7286

87+
it('should detect () syntax only if an attribute name starts and ends with ()', () => {
88+
expect(createPipeline().process(el('<div z(a)="b()"></div>'))[0].propertyBindings).toBe(null);
89+
expect(createPipeline().process(el('<div (a)v="b()"></div>'))[0].propertyBindings).toBe(null);
90+
});
91+
7392
it('should parse event handlers using () syntax as actions', () => {
7493
var results = createPipeline().process(el('<div (click)="foo=bar"></div>'));
7594
expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('foo=bar');

0 commit comments

Comments
 (0)