From e0710c4613ba51f008bc8a2f4874fb1fade9d09f Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 18 Mar 2015 21:27:46 +0100 Subject: [PATCH] fix(PropertyBindingParser): detect bindings using full attribute name Fixes #1001 Closes #1004 --- .../pipeline/property_binding_parser.js | 2 +- .../pipeline/property_binding_parser_spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/core/compiler/pipeline/property_binding_parser.js b/modules/angular2/src/core/compiler/pipeline/property_binding_parser.js index 3914ab335f..b9de3c6413 100644 --- a/modules/angular2/src/core/compiler/pipeline/property_binding_parser.js +++ b/modules/angular2/src/core/compiler/pipeline/property_binding_parser.js @@ -17,7 +17,7 @@ import {CompileControl} from './compile_control'; // Group 7 = "#" // Group 8 = identifier after "#" var BIND_NAME_REGEXP = RegExpWrapper.create( - '^(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+)'); + '^(?:(?:(?:(bind)|(var)|(on))-(.+))|\\[([^\\]]+)\\]|\\(([^\\)]+)\\)|(#)(.+))$'); /** * Parses the property bindings on a single element. diff --git a/modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js b/modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js index 7a9d8f78c5..0baea9d41c 100644 --- a/modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js +++ b/modules/angular2/test/core/compiler/pipeline/property_binding_parser_spec.js @@ -25,11 +25,20 @@ export function main() { expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b'); }); + it('should detect [] syntax only if an attribute name starts and ends with []', () => { + expect(createPipeline().process(el('
'))[0].propertyBindings).toBe(null); + expect(createPipeline().process(el('
'))[0].propertyBindings).toBe(null); + }); + it('should detect bind- syntax', () => { var results = createPipeline().process(el('
')); expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b'); }); + it('should detect bind- syntax only if an attribute name starts with bind', () => { + expect(createPipeline().process(el('
'))[0].propertyBindings).toBe(null); + }); + it('should detect interpolation syntax', () => { // Note: we don't test all corner cases of interpolation as we assume shared functionality between text interpolation // and attribute interpolation. @@ -62,6 +71,11 @@ export function main() { expect(MapWrapper.get(results[0].variableBindings, '\$implicit')).toEqual('george'); }); + it('should detect variable bindings only if an attribute name starts with #', () => { + var results = createPipeline().process(el('

')); + expect(results[0].variableBindings).toBe(null); + }); + it('should detect () syntax', () => { var results = createPipeline().process(el('
')); expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('b()'); @@ -70,6 +84,11 @@ export function main() { expect(MapWrapper.get(results[0].eventBindings, 'click[]').source).toEqual('b()'); }); + it('should detect () syntax only if an attribute name starts and ends with ()', () => { + expect(createPipeline().process(el('
'))[0].propertyBindings).toBe(null); + expect(createPipeline().process(el('
'))[0].propertyBindings).toBe(null); + }); + it('should parse event handlers using () syntax as actions', () => { var results = createPipeline().process(el('
')); expect(MapWrapper.get(results[0].eventBindings, 'click').source).toEqual('foo=bar');