Skip to content

Commit

Permalink
fix(fetch): encode parameters in source URL (#817)
Browse files Browse the repository at this point in the history
* fix(fetch): encode parameters in source URL

* chore(temp): create openapi.json

* fix: do this instead

looks like ampersands are escaped by default, this looks like the move

* chore: test name

* revert: remove dummy file

* Revert "fix: do this instead"

This reverts commit 4b0075b.
  • Loading branch information
kanadgupta authored Jun 2, 2023
1 parent d99c98e commit ff86384
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 25 additions & 0 deletions __tests__/lib/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ describe('#fetch()', () => {
mock.done();
});

it('should include source URL header with path that contains weird characters', async () => {
const key = 'API_KEY';

const mock = getAPIMock()
.get('/api/v1')
.basicAuth({ user: key })
.reply(200, function () {
return this.req.headers;
});

const headers = await readmeAPIFetch(
'/api/v1',
{
method: 'get',
headers: cleanHeaders(key),
},
{ filePath: './📈 Dashboard & Metrics/openapi.json', fileType: 'path' }
).then(handleRes);

expect(headers['x-readme-source-url'].shift()).toBe(
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/%F0%9F%93%88%20Dashboard%20&%20Metrics/openapi.json'
);
mock.done();
});

it('should include source URL header with relative path', async () => {
const key = 'API_KEY';

Expand Down
4 changes: 3 additions & 1 deletion src/lib/readmeAPIFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export default async function readmeAPIFetch(
*/
headers.set(
'x-readme-source-url',
`${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/${filePath}`
encodeURI(
`${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHA}/${filePath}`
)
);
}
}
Expand Down

0 comments on commit ff86384

Please sign in to comment.