diff --git a/lib/manager/bundler/extract.ts b/lib/manager/bundler/extract.ts index 1e25e0bc428f3d9a90681f19ed3b90c2de713cb4..a26b1554efa0ab4298ebbce3f238f3f6a0984c64 100644 --- a/lib/manager/bundler/extract.ts +++ b/lib/manager/bundler/extract.ts @@ -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'; } diff --git a/test/manager/bundler/__snapshots__/extract.spec.ts.snap b/test/manager/bundler/__snapshots__/extract.spec.ts.snap index e3068f1be1eda95dc8282acde56b3db5c342693f..7a8160369c798b87529c78638145ee2730072e84 100644 --- a/test/manager/bundler/__snapshots__/extract.spec.ts.snap +++ b/test/manager/bundler/__snapshots__/extract.spec.ts.snap @@ -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 [], +} +`; diff --git a/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines b/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines new file mode 100644 index 0000000000000000000000000000000000000000..879438f90c67286d76393941e7b44da3020798e4 --- /dev/null +++ b/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' do + gem 'rubocop' + + gem 'brakeman' +end \ No newline at end of file diff --git a/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines.lock b/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines.lock new file mode 100644 index 0000000000000000000000000000000000000000..de2775b9b83732bdfa63b0b13b39300dd6f388a5 --- /dev/null +++ b/test/manager/bundler/_fixtures/Gemfile.sourceBlockWithNewLines.lock @@ -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 \ No newline at end of file diff --git a/test/manager/bundler/extract.spec.ts b/test/manager/bundler/extract.spec.ts index f58ba3096b04672706a8e23f275be2b48ac8ec0c..5f12548bdd53cdf320fa21f28e13b8eba8d99633 100644 --- a/test/manager/bundler/extract.spec.ts +++ b/test/manager/bundler/extract.spec.ts @@ -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; @@ -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); + }); });