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: crash when analyzing node package with a local dependency #5235

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
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ private void processDependencies(JsonObject json, File baseDir, File rootFile,

if (entry.getValue() instanceof JsonObject) {
jo = (JsonObject) entry.getValue();

// Ignore/skip linked entries (as they don't have "version" and
// later logic will crash)
if (jo.getBoolean("link", false)) {
continue;
jeremylong marked this conversation as resolved.
Show resolved Hide resolved
}

version = jo.getString("version");
optional = jo.getBoolean("optional", false);
isDev = jo.getBoolean("dev", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,26 @@ public void testPackageLockV3() throws AnalysisException, InvalidSettingExceptio
analyzer.analyze(packageLockJson, engine);
assertEquals("Expected 1 dependencies", 6, engine.getDependencies().length);
}

/**
* Test of analysis of package with a local package as a dependency.
*
* This test crashes with an NPE if issue #1947 isn't resolved.
*
* @throws AnalysisException if there was a problem with the analysis
*/
@Test
public void testLocalPackageDependency() throws AnalysisException, InvalidSettingException {
Assume.assumeThat(getSettings().getBoolean(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED), is(true));
final Dependency packageJson = new Dependency(BaseTest.getResourceAsFile(this,
"nodejs/local_package/package.json"));
final Dependency packageLockJson = new Dependency(BaseTest.getResourceAsFile(this,
"nodejs/local_package/package-lock.json"));
engine.addDependency(packageJson);
engine.addDependency(packageLockJson);
analyzer.analyze(packageJson, engine);
assertEquals("Expected 1 dependencies", 1, engine.getDependencies().length);
analyzer.analyze(packageLockJson, engine);
assertEquals("Expected 2 dependencies", 2, engine.getDependencies().length);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "mypackage",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions core/src/test/resources/nodejs/local_package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions core/src/test/resources/nodejs/local_package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "local_package",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mypackage": "file:./mypackage"
}
}