Closed onury closed 5 years ago
This line:
this.path = path.replace(pageBase, '') || '/'
changes the path incorrectly by replacing (removing) the pageBase - first occurrence. It should remove the most left only, if there is any.
path
pageBase
For example,
var pageBase = "/"; var path = "my/route/"; path.replace(pageBase, ''); // ——» produces "myroute/"
We need to escape regexp characters within pageBase:
function escapeRegExp(s) { return s.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1') }
Then change the buggy line with:
// we'll ensure it only matches the start of the string. var re = new RegExp('^' + escapeRegExp(pageBase)); this.path = path.replace(re, '') || '/';
Problem
This line:
changes the
path
incorrectly by replacing (removing) thepageBase
- first occurrence. It should remove the most left only, if there is any.For example,
Solution
We need to escape regexp characters within pageBase:
Then change the buggy line with: