rethinking my UriPattern regexp

2007-12-13 @ 19:01#

this evening i decided to re-think the regular expression routines for the UriPattern custom attribute in exyus. i actually backed off a recent change that attempted to simplify the regex needed to map a resource class to URIs. it's now back to the way it was a month ago. and i think it's better this way.

this is all due to some issues in mapping IIS and ASP.NET [sigh]. IIS maps requests to code handlers using the file extension in the URL of the request. man that stinks! so all the exyus code uses .xcs as the extension. simple. but, of course, i don't *want* file extensions in my URLs - it's terrible! so i use ISAPI Rewrite (the mod_rewrite of the Windows OS) to handle this detail. users type in clean URLs, my rewriter fixes them to '.xcs URLs' and IIS then knows what to do. heck, even the WCF library from MS has the same issues (they use .svc).

but then, in the exyus classes, you need to use regex patterns (ala rewrite) to map resource classes to URLs. all the URLs coming into exyus have .xcs' added (by the rewrite), so programmers had to keep this in mind when writing UriPattern rules. messy. so i added code in the exyus engine that *stripped out* the '.xcs' from incoming URLs before handing them to the code pile. cute, but brittle.

turns out removing the '.xcs' made writing valid expressions a bit harder. now i guess i understasnd why IIS does it this way. it's much easier if you can *count on* the file extension being a part of the URL. you can use it as an 'anchor' around which to code your rules to pull the path, document, and various parts of the query string. yeah, i see that now.

so i put the '.xcs' back into the patterns. and they are much easier to write now. guess that's a lesson learned.