From 9d61733ef090ca84960b1adcf24ede656bb6ec63 Mon Sep 17 00:00:00 2001 From: Roc <rocwind@gmail.com> Date: Tue, 11 Aug 2020 04:16:07 +0800 Subject: [PATCH] fix(go): match go-source by go module prefix (#6930) --- lib/datasource/go/__snapshots__/index.spec.ts.snap | 14 ++++++++++++++ lib/datasource/go/index.spec.ts | 10 ++++++++++ lib/datasource/go/index.ts | 8 ++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/datasource/go/__snapshots__/index.spec.ts.snap b/lib/datasource/go/__snapshots__/index.spec.ts.snap index 713b35b5c1..9789204307 100644 --- a/lib/datasource/go/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/go/__snapshots__/index.spec.ts.snap @@ -14,6 +14,20 @@ Array [ ] `; +exports[`datasource/go getDigest returns null for no go-source tag 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate", + "host": "golang.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://golang.org/y/text?go-get=1", + }, +] +`; + exports[`datasource/go getDigest returns null for wrong name 1`] = ` Array [ Object { diff --git a/lib/datasource/go/index.spec.ts b/lib/datasource/go/index.spec.ts index 72f93f282b..eacac1a4f1 100644 --- a/lib/datasource/go/index.spec.ts +++ b/lib/datasource/go/index.spec.ts @@ -34,6 +34,16 @@ describe('datasource/go', () => { }); describe('getDigest', () => { + it('returns null for no go-source tag', async () => { + httpMock + .scope('https://golang.org/') + .get('/y/text?go-get=1') + .reply(200, ''); + github.getDigest.mockResolvedValueOnce('abcdefabcdefabcdefabcdef'); + const res = await getDigest({ lookupName: 'golang.org/y/text' }, null); + expect(res).toBeNull(); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); it('returns null for wrong name', async () => { httpMock .scope('https://golang.org/') diff --git a/lib/datasource/go/index.ts b/lib/datasource/go/index.ts index 0d1b42449c..f2299a6d81 100644 --- a/lib/datasource/go/index.ts +++ b/lib/datasource/go/index.ts @@ -37,10 +37,14 @@ async function getDatasource(goModule: string): Promise<DataSource | null> { const pkgUrl = `https://${goModule}?go-get=1`; const res = (await http.get(pkgUrl)).body; const sourceMatch = regEx( - `<meta\\s+name="go-source"\\s+content="${goModule}\\s+([^\\s]+)` + `<meta\\s+name="go-source"\\s+content="([^\\s]+)\\s+([^\\s]+)` ).exec(res); if (sourceMatch) { - const [, goSourceUrl] = sourceMatch; + const [, prefix, goSourceUrl] = sourceMatch; + if (!goModule.startsWith(prefix)) { + logger.trace({ goModule }, 'go-source header prefix not match'); + return null; + } logger.debug({ goModule, goSourceUrl }, 'Go lookup source url'); if (goSourceUrl?.startsWith('https://github.com/')) { return { -- GitLab