From c83eb54d7f3a1c5b4c6a82a66a12e73b9dcd3e8c Mon Sep 17 00:00:00 2001 From: jose-ws <80274739+jose-ws@users.noreply.github.com> Date: Mon, 10 May 2021 16:27:59 -0400 Subject: [PATCH] fix(pip_requirements): handle whitespace around == (#9910) --- .../__snapshots__/extract.spec.ts.snap | 40 +++++++++++++++++-- lib/manager/pip_requirements/extract.spec.ts | 14 +++++++ lib/manager/pip_requirements/extract.ts | 5 ++- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap b/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap index a33d994db1..325dfdbde1 100644 --- a/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap +++ b/lib/manager/pip_requirements/__snapshots__/extract.spec.ts.snap @@ -115,7 +115,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -161,7 +162,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -207,7 +209,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, @@ -237,6 +240,34 @@ Object { } `; +exports[`manager/pip_requirements/extract extractPackageFile() handles extra spaces around pinned dependency equal signs 1`] = ` +Object { + "deps": Array [ + Object { + "currentValue": "==2.0.12", + "currentVersion": "2.0.12", + "datasource": "pypi", + "depName": "Django", + }, + Object { + "currentValue": "==4.1.1", + "currentVersion": "4.1.1", + "datasource": "pypi", + "depName": "celery", + }, + Object { + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", + "datasource": "pypi", + "depName": "foo", + }, + ], + "registryUrls": Array [ + "https://artifactory.company.com/artifactory/api/pypi/python/simple", + ], +} +`; + exports[`manager/pip_requirements/extract extractPackageFile() handles extras and complex index url 1`] = ` Object { "deps": Array [ @@ -253,7 +284,8 @@ Object { "depName": "celery", }, Object { - "currentValue": " == 3.2.1", + "currentValue": "== 3.2.1", + "currentVersion": "3.2.1", "datasource": "pypi", "depName": "foo", }, diff --git a/lib/manager/pip_requirements/extract.spec.ts b/lib/manager/pip_requirements/extract.spec.ts index 259455bb1f..4fba3ee3ea 100644 --- a/lib/manager/pip_requirements/extract.spec.ts +++ b/lib/manager/pip_requirements/extract.spec.ts @@ -88,6 +88,20 @@ describe(getName(), () => { ]); expect(res.deps).toHaveLength(6); }); + + it('handles extra spaces around pinned dependency equal signs', () => { + const res = extractPackageFile(requirements4, 'unused_file_name', {}); + expect(res).toMatchSnapshot(); + + expect(res.deps[0].currentValue).toStartWith('=='); + expect(res.deps[0].currentVersion).toStartWith('2.0.12'); + expect(res.deps[1].currentValue).toStartWith('=='); + expect(res.deps[1].currentVersion).toStartWith('4.1.1'); + expect(res.deps[2].currentValue).toStartWith('=='); + expect(res.deps[2].currentVersion).toStartWith('3.2.1'); + + expect(res.deps).toHaveLength(3); + }); it('should not replace env vars in low trust mode', () => { process.env.PIP_TEST_TOKEN = 'its-a-secret'; const res = extractPackageFile(requirements7, 'unused_file_name', {}); diff --git a/lib/manager/pip_requirements/extract.ts b/lib/manager/pip_requirements/extract.ts index 87fc491b41..f5e357bbea 100644 --- a/lib/manager/pip_requirements/extract.ts +++ b/lib/manager/pip_requirements/extract.ts @@ -63,7 +63,8 @@ export function extractPackageFile( if (!matches) { return null; } - const [, depName, , currentValue] = matches; + const [, depName, , currVal] = matches; + const currentValue = currVal.trim(); dep = { ...dep, depName, @@ -71,7 +72,7 @@ export function extractPackageFile( datasource: datasourcePypi.id, }; if (currentValue?.startsWith('==')) { - dep.currentVersion = currentValue.replace(/^==/, ''); + dep.currentVersion = currentValue.replace(/^==\s*/, ''); } return dep; }) -- GitLab