Skip to content

Commit 8eeab50

Browse files
committed
secure looping by checking libs existence in manifest
simplify manifest path resolving
1 parent fd6a8e9 commit 8eeab50

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

lib/processors/versionInfoGenerator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const processManifest = async (manifestResource) => {
5858
// sap.ui5/dependencies is used for the "manifestHints/libs"
5959
if (manifestObject["sap.ui5"]) {
6060
const manifestDependencies = manifestObject["sap.ui5"]["dependencies"];
61-
if (manifestDependencies) {
61+
if (manifestDependencies && manifestDependencies.libs) {
6262
const libs = {};
6363
for (const [libKey, libValue] of Object.entries(manifestDependencies.libs)) {
6464
libs[libKey] = {};
@@ -134,8 +134,7 @@ const isBundledWithLibrary = (embeddedBy, componentPath, libraryPathPrefix) => {
134134
* @returns {string} manifest path, e.g. "lib/x/sub/manifest.json"
135135
*/
136136
const getManifestPath = (filePath, subPath) => {
137-
const folderPathOfManifest = filePath.substr(0, filePath.length - "manifest.json".length) + subPath;
138-
return posixPath.resolve(folderPathOfManifest + "/manifest.json");
137+
return posixPath.resolve(posixPath.dirname(filePath), subPath, "manifest.json");
139138
};
140139

141140
/**
@@ -189,6 +188,9 @@ class DependencyInfo {
189188
if (!this._libsResolved) {
190189
// early set if there is a potential cycle
191190
this._libsResolved = Object.create(null);
191+
if (!this.libs) {
192+
return this._libsResolved;
193+
}
192194
for (const [libName, libValue] of Object.entries(this.libs)) {
193195
const lazy = libValue.lazy;
194196
const dependencyInfoObjectAdded = this.addResolvedLibDependency(libName, lazy);

test/lib/processors/versionInfoGenerator.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,53 @@ test.serial("versionInfoGenerator simple library infos", async (t) => {
9090
"Cannot add meta information for library 'my.lib'. The manifest.json file cannot be found");
9191
});
9292

93+
test.serial("versionInfoGenerator manifest without libs", async (t) => {
94+
const libAManifest = {
95+
getPath: () => {
96+
return "/resources/lib/a/manifest.json";
97+
},
98+
getString: async () => {
99+
return JSON.stringify({
100+
"sap.app": {
101+
"id": "lib.a",
102+
"embeds": []
103+
},
104+
"sap.ui5": {
105+
"dependencies": {
106+
"minUI5Version": "1.84"
107+
}
108+
}
109+
});
110+
}
111+
};
112+
const libA = {name: "lib.a", version: "1.2.3", libraryManifest: libAManifest};
113+
114+
const options = {
115+
rootProjectName: "myname", rootProjectVersion: "1.33.7", libraryInfos: [
116+
libA
117+
]};
118+
const versionInfos = await versionInfoGenerator({options});
119+
120+
const resource = versionInfos[0];
121+
const result = await resource.getString();
122+
123+
const oExpected = {
124+
"name": "myname",
125+
"version": "1.33.7",
126+
"scmRevision": "",
127+
"libraries": [
128+
{
129+
"name": "lib.a",
130+
"version": "1.2.3",
131+
"scmRevision": ""
132+
}
133+
]
134+
};
135+
assertVersionInfoContent(t, oExpected, result);
136+
t.is(t.context.infoLogStub.callCount, 0);
137+
t.is(t.context.warnLogStub.callCount, 0);
138+
});
139+
93140
test.serial("versionInfoGenerator library infos with dependencies", async (t) => {
94141
const libAManifest = {
95142
getPath: () => {

0 commit comments

Comments
 (0)