Skip to content

Commit

Permalink
Prevent hash from being part of the ctx.pathname
Browse files Browse the repository at this point in the history
As with the `URL()` constructor, we should leave the hash out of the
pathname. Fixes #375
  • Loading branch information
matthewp committed Jan 16, 2018
1 parent ceea74e commit bc52c50
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
if (!hashbang) {
if (!~this.path.indexOf('#')) return;
var parts = this.path.split('#');
this.path = parts[0];
this.path = this.pathname = parts[0];
this.hash = decodeURLEncodedURIComponent(parts[1]) || '';
this.querystring = this.querystring.split('#')[0];
}
Expand Down
9 changes: 9 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@
page('/blog/post/something');
});

it('should not include hash in ctx.pathname', function(done){
page('/contact', function(ctx){
expect(ctx.pathname).to.equal('/contact');
done();
});

page(hashbang ? '/contact' : '/contact#bang');
});

describe('when next() is invoked', function() {
it('should invoke subsequent matching middleware', function(done) {

Expand Down

0 comments on commit bc52c50

Please sign in to comment.