Skip to content

Commit

Permalink
Add support for question-marks in hash fragments
Browse files Browse the repository at this point in the history
From [rfc3986](https://tools.ietf.org/html/rfc3986#section-3.5):

> The characters slash ("/") and question mark ("?") are allowed to
> represent data within the fragment identifier.
  • Loading branch information
gigabo committed Jun 27, 2016
1 parent 32c05fe commit ae09616
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,20 @@ Route.prototype.match = function (url, options) {

// 2. check path
// remove query string and hash fragment from url
var pos = url.indexOf('?');
var path;
if (pos >= 0) {
// remove query string
path = url.substring(0, pos);
} else {
pos = url.indexOf('#');
//
// hash fragment does not get sent to server.
// But since routr can be used on both server and client,
// we should remove hash fragment before matching the regex.
var path = url;
var pos;

// Leave `pos` at the beginning of the query-string, if any.
['#', '?'].forEach(function(delimiter){
pos = url.indexOf(delimiter);
if (pos >= 0) {
// hash fragment does not get sent to server.
// But since routr can be used on both server and client,
// we should remove hash fragment before matching the regex.
path = url.substring(0, pos);
} else {
path = url;
path = path.substring(0, pos);
}
}
});

var pathMatches = self.regexp.exec(path);
if (!pathMatches) {
Expand Down

0 comments on commit ae09616

Please sign in to comment.