Skip to content

Commit

Permalink
fix: decode path parts in local web server (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Dec 18, 2021
1 parent c9007cb commit 4696a0c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ async function handleRequest(
options: WebServerOptions
) {
const url = new URL(req.url || '/', `http://localhost:${options.port}`);
const pathParts = url.pathname.split('/').filter(x => !!x);
const pathParts = url.pathname
.split('/')
.filter(x => !!x)
.map(decodeURIComponent);
const originalPath = path.join(root, ...pathParts);
if (url.pathname.endsWith('/')) {
pathParts.push('index.html');
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/urlpatterns/funky+path.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<body>:waves:</body>
</html>
3 changes: 3 additions & 0 deletions test/fixtures/urlpatterns/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<html>
<body><a href="funky%2Bpath.html">url with a +</a></body>
</html>
8 changes: 8 additions & 0 deletions test/test.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,12 @@ describe('linkinator', () => {
const results = await check({path: 'test/fixtures/srcset'});
assert.ok(results.passed);
});

it('should handle encoded urls', async () => {
const results = await check({
serverRoot: 'test/fixtures/urlpatterns',
path: 'index.html',
});
assert.ok(results.passed);
});
});

0 comments on commit 4696a0c

Please sign in to comment.