@@ -75,7 +75,7 @@ func (n *Node) Add(key string, val interface{}) error {
75
75
// Adds a leaf to a terminal node.
76
76
// If the last wildcard contains an extension, add it to the 'extensions' map.
77
77
func (n * Node ) addLeaf (leaf * Leaf ) error {
78
- extension := stripExtensionFromSegments (leaf .Wildcards )
78
+ extension := stripExtensionFromLastSegment (leaf .Wildcards )
79
79
if extension != "" {
80
80
if n .extensions == nil {
81
81
n .extensions = make (map [string ]* Leaf )
@@ -154,9 +154,9 @@ func (n *Node) find(elements, exp []string) (leaf *Leaf, expansions []string) {
154
154
// If this node has explicit extensions, check if the path matches one.
155
155
if len (exp ) > 0 && n .extensions != nil {
156
156
lastExp := exp [len (exp )- 1 ]
157
- extension , splitPosition := extensionForPath (lastExp )
157
+ prefix , extension := extensionForPath (lastExp )
158
158
if leaf := n .extensions [extension ]; leaf != nil {
159
- exp [len (exp )- 1 ] = lastExp [ 0 : splitPosition ]
159
+ exp [len (exp )- 1 ] = prefix
160
160
return leaf , exp
161
161
}
162
162
}
@@ -194,12 +194,12 @@ func (n *Node) find(elements, exp []string) (leaf *Leaf, expansions []string) {
194
194
return
195
195
}
196
196
197
- func extensionForPath (path string ) (string , int ) {
198
- dotPosition := strings .Index (path , "." )
197
+ func extensionForPath (path string ) (string , string ) {
198
+ dotPosition := strings .LastIndex (path , "." )
199
199
if dotPosition != - 1 {
200
- return path [dotPosition : ], dotPosition
200
+ return path [: dotPosition ], path [ dotPosition :]
201
201
}
202
- return "" , - 1
202
+ return "" , ""
203
203
}
204
204
205
205
func splitPath (key string ) []string {
@@ -213,16 +213,16 @@ func splitPath(key string) []string {
213
213
return elements
214
214
}
215
215
216
- // stripExtensionFromSegments determines if a string slice representing a path
216
+ // stripExtensionFromLastSegment determines if a string slice representing a path
217
217
// ends with a file extension, removes the extension from the input, and returns it.
218
- func stripExtensionFromSegments (segments []string ) string {
218
+ func stripExtensionFromLastSegment (segments []string ) string {
219
219
if len (segments ) == 0 {
220
220
return ""
221
221
}
222
222
lastSegment := segments [len (segments )- 1 ]
223
- extension , splitPosition := extensionForPath (lastSegment )
223
+ prefix , extension := extensionForPath (lastSegment )
224
224
if extension != "" {
225
- segments [len (segments )- 1 ] = lastSegment [ 0 : splitPosition ]
225
+ segments [len (segments )- 1 ] = prefix
226
226
}
227
227
return extension
228
228
}
0 commit comments