@@ -96,45 +96,45 @@ function parsePathString(route: string): {[key: string]: any} {
9696
9797 var segments = splitBySlash ( route ) ;
9898 var results = [ ] ;
99- var specificity = 0 ;
99+
100+ var specificity = '' ;
101+
102+ // a single slash (or "empty segment" is as specific as a static segment
103+ if ( segments . length == 0 ) {
104+ specificity += '2' ;
105+ }
100106
101107 // The "specificity" of a path is used to determine which route is used when multiple routes match
102- // a URL.
103- // Static segments (like "/foo") are the most specific, followed by dynamic segments (like
104- // "/:id"). Star segments
105- // add no specificity. Segments at the start of the path are more specific than proceeding ones.
108+ // a URL. Static segments (like "/foo") are the most specific, followed by dynamic segments (like
109+ // "/:id"). Star segments add no specificity. Segments at the start of the path are more specific
110+ // than proceeding ones.
111+ //
106112 // The code below uses place values to combine the different types of segments into a single
107- // integer that we can
108- // sort later. Each static segment is worth hundreds of points of specificity (10000, 9900, ...,
109- // 200), and each
110- // dynamic segment is worth single points of specificity (100, 99, ... 2).
111- if ( segments . length > 98 ) {
112- throw new BaseException ( `'${ route } ' has more than the maximum supported number of segments.` ) ;
113- }
113+ // string that we can sort later. Each static segment is marked as a specificity of "2," each
114+ // dynamic segment is worth "1" specificity, and stars are worth "0" specificity.
114115
115116 var limit = segments . length - 1 ;
116117 for ( var i = 0 ; i <= limit ; i ++ ) {
117118 var segment = segments [ i ] , match ;
118119
119120 if ( isPresent ( match = RegExpWrapper . firstMatch ( paramMatcher , segment ) ) ) {
120121 results . push ( new DynamicSegment ( match [ 1 ] ) ) ;
121- specificity += ( 100 - i ) ;
122+ specificity += '1' ;
122123 } else if ( isPresent ( match = RegExpWrapper . firstMatch ( wildcardMatcher , segment ) ) ) {
123124 results . push ( new StarSegment ( match [ 1 ] ) ) ;
125+ specificity += '0' ;
124126 } else if ( segment == '...' ) {
125127 if ( i < limit ) {
126128 throw new BaseException ( `Unexpected "..." before the end of the path for "${ route } ".` ) ;
127129 }
128130 results . push ( new ContinuationSegment ( ) ) ;
129131 } else {
130132 results . push ( new StaticSegment ( segment ) ) ;
131- specificity += 100 * ( 100 - i ) ;
133+ specificity += '2' ;
132134 }
133135 }
134- var result = StringMapWrapper . create ( ) ;
135- StringMapWrapper . set ( result , 'segments' , results ) ;
136- StringMapWrapper . set ( result , 'specificity' , specificity ) ;
137- return result ;
136+
137+ return { 'segments' : results , 'specificity' : specificity } ;
138138}
139139
140140// this function is used to determine whether a route config path like `/foo/:id` collides with
@@ -177,7 +177,7 @@ function assertPath(path: string) {
177177 */
178178export class PathRecognizer {
179179 private _segments : Segment [ ] ;
180- specificity : number ;
180+ specificity : string ;
181181 terminal : boolean = true ;
182182 hash : string ;
183183
0 commit comments