diff --git a/lib/lbt/analyzer/XMLTemplateAnalyzer.js b/lib/lbt/analyzer/XMLTemplateAnalyzer.js
index faa819b1f..5a3aa8e89 100644
--- a/lib/lbt/analyzer/XMLTemplateAnalyzer.js
+++ b/lib/lbt/analyzer/XMLTemplateAnalyzer.js
@@ -162,6 +162,12 @@ class XMLTemplateAnalyzer {
return;
}
+ if ( !result ) {
+ // Handle empty xml views/fragments
+ reject(new Error("Invalid empty XML document: " + info.name));
+ return;
+ }
+
// console.log(result);
// clear();
if ( isFragment ) {
diff --git a/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js b/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
index 40069981b..1b8485a84 100644
--- a/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
+++ b/test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
@@ -3,6 +3,10 @@ const XMLTemplateAnalyzer = require("../../../../lib/lbt/analyzer/XMLTemplateAna
const ModuleInfo = require("../../../../lib/lbt/resources/ModuleInfo");
const sinon = require("sinon");
+const fakeMockPool = {
+ findResource: () => Promise.resolve()
+};
+
test("integration: Analysis of an xml view", async (t) => {
const xml = `
@@ -13,15 +17,10 @@ test("integration: Analysis of an xml view", async (t) => {
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -39,15 +38,10 @@ test("integration: Analysis of an xml view with data binding in properties", asy
controllerName="myController">
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -70,15 +64,10 @@ test("integration: Analysis of an xml view with core:require", async (t) => {
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -104,15 +93,10 @@ test("integration: Analysis of an xml view with core:require (invalid module nam
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -135,15 +119,10 @@ test("integration: Analysis of an xml view with core:require (parsing error)", a
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -165,15 +144,10 @@ test("integration: Analysis of an xml fragment", async (t) => {
`;
- const mockPool = {async findResource(name) {
- return {
- buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
- };
- }};
const moduleInfo = new ModuleInfo();
- const analyzer = new XMLTemplateAnalyzer(mockPool);
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeFragment(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -185,6 +159,18 @@ test("integration: Analysis of an xml fragment", async (t) => {
"Implicit dependency should be added since a fragment is analyzed");
});
+test("integration: Analysis of an empty xml view", async (t) => {
+ const xml = "";
+
+ const moduleInfo = new ModuleInfo("empty.xml");
+
+ const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
+
+ await t.throwsAsync(analyzer.analyzeView(xml, moduleInfo), {
+ message: "Invalid empty XML document: empty.xml"
+ }, "Should throw an error for empty XML views");
+});
+
test("_addDependency: self reference", (t) => {
const moduleInfo = {
addDependency: function() {},