Describe the bug
If tc.downloadTool is used with a url that returns a relative redirect then the function fails with the error: TypeError: Invalid URL as it attempts to parse the relative url as an absolute url.
To Reproduce
Steps to reproduce the behavior:
- Apply this patch with a test to check the behaviour:
diff --git a/packages/tool-cache/__tests__/tool-cache.test.ts b/packages/tool-cache/__tests__/tool-cache.test.ts
index 4712ab5f..c4329275 100644
--- a/packages/tool-cache/__tests__/tool-cache.test.ts
+++ b/packages/tool-cache/__tests__/tool-cache.test.ts
@@ -111,6 +111,22 @@ describe('@actions/tool-cache', function () {
expect(fs.statSync(downPath).size).toBe(35)
})
+ it('downloads a 35 byte file after a relative redirect', async () => {
+ nock('http://example.com')
+ .persist()
+ .get('/relative-redirect')
+ .reply(303, undefined, {
+ location: 'bytes/35'
+ })
+
+ const downPath: string = await tc.downloadTool(
+ 'http://example.com/relative-redirect'
+ )
+
+ expect(fs.existsSync(downPath)).toBeTruthy()
+ expect(fs.statSync(downPath).size).toBe(35)
+ })
+
it('handles error from response message stream', async () => {
nock('http://example.com')
.persist()
- Run the repository tests and view the
TypeError: Invalid URL failure.
Expected behavior
The relative location should be resolved with the current url as the base instead of as an absolute url.
Additional context
The support for relative redirects is missing in the @actions/http-client package.
Describe the bug
If
tc.downloadToolis used with a url that returns a relative redirect then the function fails with the error:TypeError: Invalid URLas it attempts to parse the relative url as an absolute url.To Reproduce
Steps to reproduce the behavior:
TypeError: Invalid URLfailure.Expected behavior
The relative location should be resolved with the current url as the base instead of as an absolute url.
Additional context
The support for relative redirects is missing in the @actions/http-client package.