Skip to content

Commit

Permalink
fix(astexplorer): accept non-SSL URLs
Browse files Browse the repository at this point in the history
Since astexplorer.net doesn't force SSL, users might be using it without SSL. When they copy the URL, it'll be `http` instead of `https`. We now accept such URLs, but turn them into `https` when normalizing them.
  • Loading branch information
eventualbuddha committed Jun 8, 2018
1 parent 3710f2f commit f87ecc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/resolvers/AstExplorerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ export default class AstExplorerResolver extends NetworkResolver {
}

private matchesHost(url: URL): boolean {
return (
url.protocol === this.baseURL.protocol && url.host === this.baseURL.host
);
if (url.host !== this.baseURL.host) {
return false;
}

// use SSL even if the URL doesn't use it
return url.protocol === this.baseURL.protocol || url.protocol === 'http:';
}
}
12 changes: 12 additions & 0 deletions test/unit/resolvers/AstExplorerResolverTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe('AstExplorerResolver', function() {
);
});

it('normalizes http gist+commit editor URL to an https API URL', async function() {
let resolver = new AstExplorerResolver();
let normalized = await resolver.normalize(
'http://astexplorer.net/#/gist/b5b33c/f9ae8a'
);

strictEqual(
normalized,
'https://astexplorer.net/api/v1/gist/b5b33c/f9ae8a'
);
});

it('normalizes a gist-only editor URL into an API URL', async function() {
let resolver = new AstExplorerResolver();
let normalized = await resolver.normalize(
Expand Down

0 comments on commit f87ecc2

Please sign in to comment.