@@ -132,6 +132,7 @@ function tokensToFunction (tokens) {
132
132
}
133
133
134
134
var value = data [ token . name ]
135
+ var segment
135
136
136
137
if ( value == null ) {
137
138
if ( token . optional ) {
@@ -143,7 +144,7 @@ function tokensToFunction (tokens) {
143
144
144
145
if ( isarray ( value ) ) {
145
146
if ( ! token . repeat ) {
146
- throw new TypeError ( 'Expected "' + token . name + '" to not repeat' )
147
+ throw new TypeError ( 'Expected "' + token . name + '" to not repeat, but received "' + value + '" ')
147
148
}
148
149
149
150
if ( value . length === 0 ) {
@@ -155,21 +156,25 @@ function tokensToFunction (tokens) {
155
156
}
156
157
157
158
for ( var j = 0 ; j < value . length ; j ++ ) {
158
- if ( ! matches [ i ] . test ( value [ j ] ) ) {
159
- throw new TypeError ( 'Expected all "' + token . name + '" to match "' + token . pattern + '"' )
159
+ segment = encodeURIComponent ( value [ j ] )
160
+
161
+ if ( ! matches [ i ] . test ( segment ) ) {
162
+ throw new TypeError ( 'Expected all "' + token . name + '" to match "' + token . pattern + '", but received "' + segment + '"' )
160
163
}
161
164
162
- path += ( j === 0 ? token . prefix : token . delimiter ) + encodeURIComponent ( value [ j ] )
165
+ path += ( j === 0 ? token . prefix : token . delimiter ) + segment
163
166
}
164
167
165
168
continue
166
169
}
167
170
168
- if ( ! matches [ i ] . test ( value ) ) {
169
- throw new TypeError ( 'Expected "' + token . name + '" to match "' + token . pattern + '"' )
171
+ segment = encodeURIComponent ( value )
172
+
173
+ if ( ! matches [ i ] . test ( segment ) ) {
174
+ throw new TypeError ( 'Expected "' + token . name + '" to match "' + token . pattern + '", but received "' + segment + '"' )
170
175
}
171
176
172
- path += token . prefix + encodeURIComponent ( value )
177
+ path += token . prefix + segment
173
178
}
174
179
175
180
return path
0 commit comments