Skip to content

Commit

Permalink
Robustify package parser against malformed package.xml (see #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
pschillinger committed Jun 14, 2019
1 parent 0db891f commit fa768c2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/io/io_packageparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,20 @@ IO.PackageParser = new (function() {
var checkForRelevance = function(pkg_path, callback) {
var package_xml_path = path.join(pkg_path, 'package.xml');

if (fs.existsSync(package_xml_path)) {
var data = fs.readFileSync(package_xml_path);
var xml = dom_parser.parseFromString(String(data), "text/xml");
var pkg_xml = xml.getElementsByTagName("package")[0];
var pkg_export = pkg_xml.getElementsByTagName("export")[0];
var hasStates = pkg_export && pkg_export.getElementsByTagName("flexbe_states").length > 0;
var hasBehaviors = pkg_export && pkg_export.getElementsByTagName("flexbe_behaviors").length > 0;
callback(hasStates, hasBehaviors);
} else {
try {
if (fs.existsSync(package_xml_path)) {
var data = fs.readFileSync(package_xml_path);
var xml = dom_parser.parseFromString(String(data), "text/xml");
var pkg_xml = xml.getElementsByTagName("package")[0];
var pkg_export = pkg_xml.getElementsByTagName("export")[0];
var hasStates = pkg_export && pkg_export.getElementsByTagName("flexbe_states").length > 0;
var hasBehaviors = pkg_export && pkg_export.getElementsByTagName("flexbe_behaviors").length > 0;
callback(hasStates, hasBehaviors);
} else {
callback(undefined, undefined);
}
} catch (e) {
T.logWarn("Skipping package "+pkg_path+" due to a malformed package.xml");
callback(undefined, undefined);
}
}
Expand Down

0 comments on commit fa768c2

Please sign in to comment.