@@ -35,7 +35,6 @@ public class Router {
35
35
* Pattern used to locate a method override instruction in request.querystring
36
36
*/
37
37
static Pattern methodOverride = new Pattern ("^.*x-http-method-override=({method}GET|PUT|POST|DELETE).*$" );
38
-
39
38
/**
40
39
* Timestamp the routes file was last loaded at.
41
40
*/
@@ -165,6 +164,11 @@ static void parse(VirtualFile routeFile, String prefix) {
165
164
// Mutable map needs to be passed in.
166
165
content = TemplateLoader .load (routeFile ).render (new HashMap <String , Object >(16 ));
167
166
}
167
+ parse (content , prefix , fileAbsolutePath );
168
+ }
169
+
170
+ static void parse (String content , String prefix , String fileAbsolutePath ) {
171
+ int lineNumber = 0 ;
168
172
for (String line : content .split ("\n " )) {
169
173
lineNumber ++;
170
174
line = line .trim ().replaceAll ("\\ s+" , " " );
@@ -225,7 +229,6 @@ public static void detectChanges(String prefix) {
225
229
}
226
230
}
227
231
}
228
-
229
232
/**
230
233
* All the loaded routes.
231
234
*/
@@ -372,7 +375,11 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
372
375
Map <String , Object > argsbackup = new HashMap <String , Object >(args );
373
376
// Add routeArgs
374
377
if (Scope .RouteArgs .current () != null ) {
375
- args .putAll (Scope .RouteArgs .current ().data );
378
+ for (String key : Scope .RouteArgs .current ().data .keySet ()) {
379
+ if (!args .containsKey (key )) {
380
+ args .put (key , Scope .RouteArgs .current ().data .get (key ));
381
+ }
382
+ }
376
383
}
377
384
for (Route route : routes ) {
378
385
if (route .actionPattern != null ) {
@@ -437,14 +444,14 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
437
444
List <Object > vals = (List <Object >) value ;
438
445
try {
439
446
path = path .replaceAll ("\\ {(<[^>]+>)?" + key + "\\ }" , URLEncoder .encode (vals .get (0 ).toString ().replace ("$" , "\\ $" ), "utf-8" ));
440
- } catch (UnsupportedEncodingException e ) {
447
+ } catch (UnsupportedEncodingException e ) {
441
448
throw new UnexpectedException (e );
442
449
}
443
450
} else {
444
451
try {
445
452
path = path .replaceAll ("\\ {(<[^>]+>)?" + key + "\\ }" , URLEncoder .encode (value .toString ().replace ("$" , "\\ $" ), "utf-8" ).replace ("%3A" , ":" ).replace ("%40" , "@" ));
446
453
host = host .replaceAll ("\\ {(<[^>]+>)?" + key + "\\ }" , URLEncoder .encode (value .toString ().replace ("$" , "\\ $" ), "utf-8" ).replace ("%3A" , ":" ).replace ("%40" , "@" ));
447
- } catch (UnsupportedEncodingException e ) {
454
+ } catch (UnsupportedEncodingException e ) {
448
455
throw new UnexpectedException (e );
449
456
}
450
457
}
@@ -506,31 +513,27 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
506
513
}
507
514
508
515
public static class ActionDefinition {
516
+
509
517
/**
510
518
* The domain/host name.
511
519
*/
512
520
public String host ;
513
-
514
521
/**
515
522
* The HTTP method, e.g. "GET".
516
523
*/
517
524
public String method ;
518
-
519
525
/**
520
526
* @todo - what is this? does it include the domain?
521
527
*/
522
528
public String url ;
523
-
524
529
/**
525
530
* Whether the route contains an astericks *.
526
531
*/
527
532
public boolean star ;
528
-
529
533
/**
530
534
* @todo - what is this? does it include the class and package?
531
535
*/
532
536
public String action ;
533
-
534
537
/**
535
538
* @todo - are these the required args in the routing file, or the query string in a request?
536
539
*/
@@ -644,7 +647,7 @@ public void compute() {
644
647
if (m .matches ()) {
645
648
if (this .host .contains ("{" )) {
646
649
String name = m .group (1 ).replace ("{" , "" ).replace ("}" , "" );
647
- if (!name .equals ("_" )) {
650
+ if (!name .equals ("_" )) {
648
651
hostArg = new Arg ();
649
652
hostArg .name = name ;
650
653
Logger .trace ("hostArg name [" + name + "]" );
@@ -703,7 +706,6 @@ public void addParams(String params) {
703
706
}
704
707
705
708
// TODO: Add args names
706
-
707
709
public void addFormat (String params ) {
708
710
if (params == null || params .length () < 1 ) {
709
711
return ;
0 commit comments