I had to read this a few times to see that 1) this is a lot of effort to escape paths for regex, and 2) the only thing this is doing that simple string comparison doesn't is the `$` anchor.

It would be more code, but I would either create a [RexExp escape function](http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript), or add a polyfil for [String.prototype.endsWith](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith).