-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from snyk/fix/local-jars-filter
fix: ignore non-jar items from jar list
- Loading branch information
Showing
5 changed files
with
67 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
parse: parse, | ||
}; | ||
|
||
function parse(text) { | ||
var ext = '.jar'; | ||
if (text && text.length) { | ||
return text.split('\n') | ||
.map(trim) | ||
.filter(function (line) { | ||
return line && line.length > ext.length && | ||
line.substr(line.length - ext.length, ext.length) === ext; | ||
}); | ||
} | ||
return []; | ||
} | ||
|
||
function trim(text) { | ||
// String.trim not available in es3 | ||
// see: https://goo.gl/EH6gh4 | ||
return text.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/functional/parse-gradle.test.js → test/functional/gradle-dep-parser.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var test = require('tap-only'); | ||
var parse = require('../../lib/gradle-jar-parser').parse; | ||
|
||
test('parse empty text', function (t) { | ||
t.same(parse(''), [], 'empty list'); | ||
t.end(); | ||
}); | ||
|
||
test('parse normal text', function (t) { | ||
var text = 'commons-cli-1.1.jar\ncommons-codec-1.6.jar\n'; | ||
var expected = [ | ||
'commons-cli-1.1.jar', | ||
'commons-codec-1.6.jar', | ||
]; | ||
t.same(parse(text), expected, 'jar list'); | ||
t.end(); | ||
}); | ||
|
||
test('parse badly formatted text', function (t) { | ||
var text = 'Extra\nMore\n commons-cli-1.1.jar \n commons-codec-1.6.jar \n'; | ||
var expected = [ | ||
'commons-cli-1.1.jar', | ||
'commons-codec-1.6.jar', | ||
]; | ||
t.same(parse(text), expected, 'jar list'); | ||
t.end(); | ||
}); |