Skip to content

Commit

Permalink
fix(bundler): Fix support for source block with new lines (#5270)
Browse files Browse the repository at this point in the history
  • Loading branch information
bilby91 committed Feb 1, 2020
1 parent 12d1b13 commit 2880682
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/manager/bundler/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function extractPackageFile(
lineNumber += 1;
sourceLine = lines[lineNumber];
// istanbul ignore if
if (!sourceLine) {
if (sourceLine === null || sourceLine === undefined) {
logger.error({ content, fileName }, 'Undefined sourceLine');
sourceLine = 'end';
}
Expand Down
33 changes: 33 additions & 0 deletions test/manager/bundler/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4688,3 +4688,36 @@ Object {
],
}
`;

exports[`lib/manager/bundler/extract parse source blocks with spaces in Gemfile 1`] = `
Object {
"compatibility": Object {
"bundler": "1.16.6",
},
"deps": Array [
Object {
"depName": "rubocop",
"lockedVersion": "0.68.1",
"managerData": Object {
"lineNumber": 3,
},
"registryUrls": Array [
"https://rubygems.org",
],
"skipReason": "no-version",
},
Object {
"depName": "brakeman",
"lockedVersion": "4.4.0",
"managerData": Object {
"lineNumber": 5,
},
"registryUrls": Array [
"https://rubygems.org",
],
"skipReason": "no-version",
},
],
"registryUrls": Array [],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org' do
gem 'rubocop'

gem 'brakeman'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
brakeman (4.4.0)
jaro_winkler (1.5.4)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
rainbow (3.0.0)
rubocop (0.68.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-progressbar (1.10.1)
unicode-display_width (1.5.0)

PLATFORMS
ruby

DEPENDENCIES
brakeman!
rubocop!

BUNDLED WITH
1.16.6
19 changes: 19 additions & 0 deletions test/manager/bundler/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ const gitlabFossGemfile = readFileSync(
'test/manager/bundler/_fixtures/Gemfile.gitlab-foss',
'utf8'
);
const sourceBlockWithNewLinesGemfileLock = readFileSync(
'test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines.lock',
'utf8'
);
const sourceBlockWithNewLinesGemfile = readFileSync(
'test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines',
'utf8'
);

function validateGems(raw, parsed) {
const gemfileGemCount = raw.match(/\n\s*gem\s+/g).length;
const parsedGemCount = parsed.deps.length;
Expand Down Expand Up @@ -147,4 +156,14 @@ describe('lib/manager/bundler/extract', () => {
).toBe(true);
validateGems(gitlabFossGemfile, res);
});

it('parse source blocks with spaces in Gemfile', async () => {
platform.getFile.mockReturnValueOnce(sourceBlockWithNewLinesGemfileLock);
const res = await extractPackageFile(
sourceBlockWithNewLinesGemfile,
'Gemfile'
);
expect(res).toMatchSnapshot();
validateGems(sourceBlockWithNewLinesGemfile, res);
});
});

0 comments on commit 2880682

Please sign in to comment.