Add tests for url matching and fix a couple of bugs uncovered in the process