File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -251,8 +251,8 @@ function EasySAXParser() {
251251 continue
252252 } ;
253253
254- if ( w < 65 || w > 122 || ( w > 90 && w < 97 ) ) { // ожидаем символ
255- //console.log('error attr 1')
254+ if ( ( w < 65 && w !== 40 && w !== 41 ) || // allow parens () -- used for angular syntax
255+ w > 122 || ( w === 92 || ( w > 93 && w < 97 ) ) ) { // ожидаем символ
256256 return attr_res = false ; // error. invalid char
257257 } ;
258258
@@ -263,10 +263,14 @@ function EasySAXParser() {
263263 continue ;
264264 } ;
265265
266- if ( w === 32 || ( w > 8 && w < 14 ) ) { // \f\n\r\t\v пробел
266+ if ( w === 32 || ( w > 8 && w < 14 ) ) { // \f\n\r\t\v пробел
267267 continue ;
268268 } ;
269269
270+ if ( w === 91 || w === 93 || w === 40 || w === 41 || w === 94 ) { // Angular special attribute chars:[]()^
271+ continue ;
272+ }
273+
270274
271275 if ( w !== 61 ) { // "=" == 61
272276 //console.log('error 2');
Original file line number Diff line number Diff line change 1+ import { assert } from "chai" ;
2+ import xml = require( 'xml' ) ;
3+
4+ describe ( "angular xml parser" , ( ) => {
5+ let last_element = null ;
6+ let last_attrs = null ;
7+ let parser = null ;
8+
9+ beforeEach ( ( ) => {
10+ parser = new xml . XmlParser ( function ( event : xml . ParserEvent ) {
11+ switch ( event . eventType ) {
12+ case xml . ParserEventType . StartElement :
13+ last_element = event . elementName ;
14+ last_attrs = event . attributes ;
15+ break ;
16+ }
17+ } ) ;
18+ } ) ;
19+
20+ it ( "parses [property] binding" , ( ) => {
21+ parser . parse ( "<TextField [text]='somevar' />" ) ;
22+
23+ assert . equal ( 'TextField' , last_element ) ;
24+ assert . equal ( last_attrs [ '[text]' ] , 'somevar' ) ;
25+ } ) ;
26+
27+ it ( "parses (event) binding" , ( ) => {
28+ parser . parse ( "<TextField (tap)='onTap(blah)' />" ) ;
29+
30+ assert . equal ( 'TextField' , last_element ) ;
31+ assert . equal ( last_attrs [ '(tap)' ] , 'onTap(blah)' ) ;
32+ } ) ;
33+
34+ it ( "parsers (^event) binding" , ( ) => {
35+ parser . parse ( "<TextField (^tap)='onTap(blah)' />" ) ;
36+
37+ assert . equal ( 'TextField' , last_element ) ;
38+ assert . equal ( last_attrs [ '(^tap)' ] , 'onTap(blah)' ) ;
39+ } ) ;
40+ } ) ;
Original file line number Diff line number Diff line change @@ -27,5 +27,4 @@ describe("xml parser", () => {
2727 assert . equal ( 'TextField' , last_element ) ;
2828 assert . equal ( 'hello' , last_attrs [ 'text' ] ) ;
2929 } ) ;
30-
3130} ) ;
Original file line number Diff line number Diff line change @@ -242,4 +242,4 @@ export class XmlParser implements definition.XmlParser {
242242
243243 return s ;
244244 }
245- }
245+ }
You can’t perform that action at this time.
0 commit comments