Using ui-router v0.2.15. Have a route in our AngularJS (v1.4.7) application setup as follows:
.state('routeState',
{
url: '/path/segment?param.sub.a¶m.sub.b¶m.sub.c',
...
}
As I understand the protocol, having periods inside of url query parameter names is valid. i.e.;
?first.name=Bobo&last.name=Muffy
When I setup this route in Angular, I get an error because the regex appears to be stripping out (or splitting up) the name portion into segments. So it essentially sees 'param.sub.a' as just 'param', and then errors out stating that 'param.sub.b' is a duplicate of 'param.sub.a' (because it only reads the 'param' portion of 'param.sub.b').
Unfortunately, we cannot change the parameter names as they are part of an existing protocol. I'm not sure if there's a workaround to resolve my problem that doesn't involve a change to the ui-router module itself.
After searching around, I cannot seem to find any other hits of people having this issue. While I did find this and this issue, they appear to be related to when the parameter values contain periods, not the parameter names.
Anyone else encountered (and hopefully solved) this issue? Hoping that I'm just missing something obvious already existing in the framework that can resolve this problem.
Update:
(Updated 11/30 to optimize modified regex)
After educating myself some on regular expressions, and then tracing the execution path of ui-router, I think I've narrowed down where this is occurring in the code, along with a possible fix.
Inside of angular-ui-router.js (v0.2.15), in the file urlMatcherFactory.js the variable searchPlaceholder is defined as follows:
searchPlaceholder = /([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g
Lower down is where any search parameters get processed by the following section of code:
if (search.length > 0) {
last = 0;
while ((m = searchPlaceholder.exec(search))) {
p = matchDetails(m, true);
param = addParameter(p.id, p.type, p.cfg, "search");
last = placeholder.lastIndex;
// check if ?&
}
}
If I replace the \w\[\]-
segments in the regex with \w\[\].-
then it appears that the periods are now included as part of the name. This was attempted after researching what characters are actually considered to be valid for URI query parameters both here and here.
I've got a post up on ui-router's GitHub page as well.
Again, there may be another way to skin this cat that is still considered to be within the framework that I'm just not seeing - so if anyone has a deeper knowledge of ui-router that might solve this without having to update the regex, I would be very thankful.