millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

[FIX] ISSUE138: S10 shouldn't match S1/:context: #149

Open stopcoder opened 8 years ago

stopcoder commented 8 years ago

The regex used for OPTIONAL SLASH is too general for some cases like S1/:context:. The slash between '1' and ':' shouldn't be optional because there's no REQUIRED SLASH or QUERY after it.

In the fix, I distinguish between the OPTIONAL SLASH and the conditionally optional slash. Only when the optional slash is before a REQUIRED SLASH or around a QUERY (either optional or required) string or followed by a static slash, it's then optional. Otherwise it's called the conditionally optional. Conditional means that it's required unless it's at the beginning or end of the pattern.

I also added tests to the match spec.

Best regards, Jiawei