Skip to content

Commit

Permalink
fix: actual fix
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosescri authored and wheresrhys committed Oct 28, 2020
1 parent 25bd1b2 commit 99ef594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/lib/request-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
let URL;
// https://stackoverflow.com/a/19709846/308237
// modified, URL constructor does not support protocol-relative urls
// split, URL constructor does not support protocol-relative urls
const absoluteUrlRX = new RegExp('^[a-z]+://', 'i');
const protocolRelativeUrlRX = new RegExp('^//', 'i');

const headersToArray = (headers) => {
// node-fetch 1 Headers
Expand All @@ -28,6 +29,9 @@ const normalizeUrl = (url) => {
if (absoluteUrlRX.test(url)) {
const u = new URL(url);
return u.href;
} else if (protocolRelativeUrlRX.test(url)) {
const u = new URL(url, 'http://dummy');
return u.href;
} else {
const u = new URL(url, 'http://dummy');
return u.pathname + u.search;
Expand Down
4 changes: 1 addition & 3 deletions test/specs/routing/url-matching.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ describe('url matching', () => {
await fm.fetchHandler('http://a.co/path');
expect(fm.calls(true).length).to.equal(0);
await fm.fetchHandler('http://a.com/path');
expect(fm.calls(true).length).to.equal(1);
// gets normalized to http://a.com/path
await fm.fetchHandler('//a.com/path');
expect(fm.calls(true).length).to.equal(1);
expect(fm.calls(true).length).to.equal(2);
});

it('match exact strings with relative url', async () => {
Expand Down

0 comments on commit 99ef594

Please sign in to comment.