Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] XMLTemplateAnalyzer: Handle empty XML view/fragment #471

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ class XMLTemplateAnalyzer {
return;
}

if ( !result ) {
// Skip empty xml views/fragments
log.warn("Ignoring empty file " + info.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't an empty view/fragment invalid? XML does not know allow empty files, IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I will change this to throw a proper error

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

resolve(info);
return;
}

// console.log(result);
// clear();
if ( isFragment ) {
Expand Down
17 changes: 17 additions & 0 deletions test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ 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 mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
codeworrior marked this conversation as resolved.
Show resolved Hide resolved
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies, [], "No dependencies should be detected");
t.false(moduleInfo.isImplicitDependency("sap/ui/core/mvc/XMLView.js"),
"No implicit dependency should be added for an empty XMLView");
});

test("_addDependency: self reference", (t) => {
const moduleInfo = {
addDependency: function() {},
Expand Down