feat(xml parser): Only allow angular syntax extensions if configured.

Configure via the public `angularSyntax` property on EasySAXParser and
the XmlParser wrapper.
This commit is contained in:
Hristo Deshev
2015-06-05 15:51:08 +03:00
parent aa112244fd
commit 748b4f1c99
5 changed files with 650 additions and 622 deletions

View File

@@ -5,6 +5,7 @@ declare module "js-libs/easysax" {
parse(xml: string): void;
on(name: string, cb: Function): void;
ns(root: string, ns: any): void;
public angularSyntax: boolean;
}
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,7 @@ describe("angular xml parser", () => {
break;
}
});
parser.angularSyntax = true;
});
it("parses [property] binding", () => {
@@ -53,7 +54,6 @@ describe("angular xml parser", () => {
assert.equal(last_attrs['text'], 'Name');
});
return
it("detects equals without value", () => {
parser.parse("<TextField brokenTag= />");
@@ -71,4 +71,11 @@ describe("angular xml parser", () => {
assert.isFalse(last_attrs);
});
it("rejects angular properties if syntax disabled", () => {
parser.angularSyntax = false;
parser.parse("<TextField [text]='somevalue' />");
assert.isFalse(last_attrs);
});
});

4
xml/xml.d.ts vendored
View File

@@ -86,7 +86,7 @@ declare module "xml" {
* @param onError The callback to execute when a parser error occurs. The 'error' parameter contains the error.
* @param processNamespaces Specifies whether namespaces should be processed.
*/
constructor(onEvent: (event: ParserEvent) => void, onError?: (error: Error) => void, processNamespaces?: boolean);
constructor(onEvent: (event: ParserEvent) => void, onError?: (error: Error) => void, processNamespaces?: boolean, angularSyntax?: boolean);
/**
* Parses the supplied xml string.
@@ -94,4 +94,4 @@ declare module "xml" {
*/
parse(xmlString: string): void;
}
}
}

View File

@@ -148,6 +148,14 @@ export class XmlParser implements definition.XmlParser {
}
}
public get angularSyntax() : boolean {
return this._parser.angularSyntax;
}
public set angularSyntax(value: boolean) {
this._parser.angularSyntax = value;
}
public parse(xmlString: string): void {
if (this._processNamespaces) {
this._namespaceStack = [];