tinganho/connect-modrewrite — pull request #39 by tikotzky (2014-08-01 04:28:47+00:00)
Title: fix url replacing when matching a partial url

Right now if you have a rule defined like `-test /abc` and `req.url = '/this-is-a-test'`
you'll end up with a `req.url` of `/this-is-a/abc`
The expected behavior in this case when using modrewrite is that the url end up being `/abc`
because the `-test` should match the url and the url should get replaced with `/abc`

This error is happening because it does a replace like `'/this-is-a-test'.replace(/-test/, '/abc')` which = `/this-is-a/abc`

This commit adds a `.*` in the beginning and end so the replace ends up being like `'/this-is-a-test'.replace(/.*-test.*/, '/abc')` which correctly = `/abc`

I also added a couple of tests to make sure that url matching works correctly when using `^` and `$`