Skip to content

Commit

Permalink
Resetting the value of lastIndex after a replace call. This is for th…
Browse files Browse the repository at this point in the history
…e sake of IE
  • Loading branch information
jbaudanza committed May 18, 2011
1 parent 8e11056 commit e0d4810
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/davis.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ Davis.Route = (function () {
var Route = function (method, path, callback) {
var convertPathToRegExp = function () {
if (!(path instanceof RegExp)) {
return new RegExp("^" + path.replace(pathNameRegex, pathNameReplacement) + "$", "gi");
var str = path.replace(pathNameRegex, pathNameReplacement);

// Most browsers will reset this to zero after a replace call. IE will
// set it to the index of the last matched character.
path.lastIndex = 0;

return new RegExp("^" + str + "$", "gi");
} else {
return path;
};
Expand Down

0 comments on commit e0d4810

Please sign in to comment.