( key: string, params: InterpolatePathOptions['params'], decoder: InterpolatePathOptions['decoder'], )
| 239 | } |
| 240 | |
| 241 | function encodeParam( |
| 242 | key: string, |
| 243 | params: InterpolatePathOptions['params'], |
| 244 | decoder: InterpolatePathOptions['decoder'], |
| 245 | ): any { |
| 246 | const value = params[key] |
| 247 | if (typeof value !== 'string') return value |
| 248 | |
| 249 | if (key === '_splat') { |
| 250 | // Early return if value only contains URL-safe characters (performance optimization) |
| 251 | if (/^[a-zA-Z0-9\-._~!/]*$/.test(value)) return value |
| 252 | // the splat/catch-all routes shouldn't have the '/' encoded out |
| 253 | // Use encodeURIComponent for each segment to properly encode spaces, |
| 254 | // plus signs, and other special characters that encodeURI leaves unencoded |
| 255 | return value |
| 256 | .split('/') |
| 257 | .map((segment) => encodePathParam(segment, decoder)) |
| 258 | .join('/') |
| 259 | } else { |
| 260 | return encodePathParam(value, decoder) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Interpolate params and wildcards into a route path template. |
no test coverage detected