diff --git a/lib/datasource/go/__snapshots__/index.spec.ts.snap b/lib/datasource/go/__snapshots__/index.spec.ts.snap index 713b35b5c12935d2b145b82a84d39bb326571924..9789204307ea93ebdbb161537a0f271ceecf7bab 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 72f93f282b86b153b7d9964caeaabb4bbeb3c916..eacac1a4f17aa3d7ac8b9147ab8c978035e49b01 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 0d1b42449c7207cafca18ce8276e6b49facd65aa..f2299a6d81c4677c3f208b7e98abaf988a3eb0c7 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 {