diff --git a/lib/datasource/sbt/index.ts b/lib/datasource/sbt/index.ts index b028ca664e089d9957e513b6702b3d675d483702..78458fc084d6e430a361f1467624ed3aa893fb11 100644 --- a/lib/datasource/sbt/index.ts +++ b/lib/datasource/sbt/index.ts @@ -4,12 +4,17 @@ import { parseIndexDir, SBT_PLUGINS_REPO } from './util'; import { logger } from '../../logger'; import { PkgReleaseConfig, ReleaseResult } from '../common'; +const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); + async function resolvePackageReleases( searchRoot: string, artifact: string, scalaVersion: string ): Promise<string[]> { - const indexContent = await downloadHttpProtocol(searchRoot, 'sbt'); + const indexContent = await downloadHttpProtocol( + ensureTrailingSlash(searchRoot), + 'sbt' + ); if (indexContent) { const releases: string[] = []; const parseSubdirs = (content: string): string[] => @@ -31,7 +36,7 @@ async function resolvePackageReleases( parseIndexDir(content, x => !/^\.+$/.test(x)); for (const searchSubdir of searchSubdirs) { const content = await downloadHttpProtocol( - `${searchRoot}/${searchSubdir}`, + ensureTrailingSlash(`${searchRoot}/${searchSubdir}`), 'sbt' ); if (content) { @@ -53,7 +58,10 @@ async function resolvePluginReleases( const searchRoot = `${rootUrl}/${artifact}`; const parse = (content: string): string[] => parseIndexDir(content, x => !/^\.+$/.test(x)); - const indexContent = await downloadHttpProtocol(searchRoot, 'sbt'); + const indexContent = await downloadHttpProtocol( + ensureTrailingSlash(searchRoot), + 'sbt' + ); if (indexContent) { const releases: string[] = []; const scalaVersionItems = parse(indexContent); @@ -64,13 +72,16 @@ async function resolvePluginReleases( : [scalaVersion]; for (const searchVersion of searchVersions) { const searchSubRoot = `${searchRoot}/scala_${searchVersion}`; - const subRootContent = await downloadHttpProtocol(searchSubRoot, 'sbt'); + const subRootContent = await downloadHttpProtocol( + ensureTrailingSlash(searchSubRoot), + 'sbt' + ); if (subRootContent) { const sbtVersionItems = parse(subRootContent); for (const sbtItem of sbtVersionItems) { const releasesRoot = `${searchSubRoot}/${sbtItem}`; const releasesIndexContent = await downloadHttpProtocol( - releasesRoot, + ensureTrailingSlash(releasesRoot), 'sbt' ); if (releasesIndexContent) { diff --git a/test/datasource/sbt/index.spec.ts b/test/datasource/sbt/index.spec.ts index 913a4167b323f8c8e79b70ec3f38e3dfd6518a0e..15c1aa3d68bb17a45720f0cc5bad81afda59e9cd 100644 --- a/test/datasource/sbt/index.spec.ts +++ b/test/datasource/sbt/index.spec.ts @@ -30,10 +30,10 @@ describe('datasource/sbt', () => { beforeEach(() => { nock.disableNetConnect(); nock('https://failed_repo') - .get('/maven/org/scalatest') + .get('/maven/org/scalatest/') .reply(404, null); nock('https://repo.maven.apache.org') - .get('/maven2/org/scalatest') + .get('/maven2/org/scalatest/') .reply( 200, '<a href="scalatest/" title=\'scalatest/\'>scalatest_2.12/</a>\n' + @@ -42,17 +42,17 @@ describe('datasource/sbt', () => { "<a href='scalatest_native2.12/'>scalatest_2.12/</a>" ); nock('https://repo.maven.apache.org') - .get('/maven2/org/scalatest/scalatest') + .get('/maven2/org/scalatest/scalatest/') .reply(200, "<a href='1.2.0/'>1.2.0/</a>"); nock('https://repo.maven.apache.org') - .get('/maven2/org/scalatest/scalatest_2.12') + .get('/maven2/org/scalatest/scalatest_2.12/') .reply(200, "<a href='1.2.3/'>4.5.6/</a>"); nock('https://dl.bintray.com') - .get('/sbt/sbt-plugin-releases/com.github.gseitz') + .get('/sbt/sbt-plugin-releases/com.github.gseitz/') .reply(200, ''); nock('https://dl.bintray.com') - .get('/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray') + .get('/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/') .reply( 200, '<html>\n' + @@ -65,7 +65,7 @@ describe('datasource/sbt', () => { ); nock('https://dl.bintray.com') .get( - '/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/scala_2.12' + '/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/scala_2.12/' ) .reply( 200, @@ -80,7 +80,7 @@ describe('datasource/sbt', () => { ); nock('https://dl.bintray.com') .get( - '/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/scala_2.12/sbt_1.0' + '/sbt/sbt-plugin-releases/org.foundweekends/sbt-bintray/scala_2.12/sbt_1.0/' ) .reply( 200,