(u: PreparedURL | null, p: PreparedPattern | null)
| 225 | } |
| 226 | |
| 227 | function matchPreparedURLPattern(u: PreparedURL | null, p: PreparedPattern | null) { |
| 228 | if ( |
| 229 | !(u && p) |
| 230 | || (p.hostParts.length > u.hostParts.length) |
| 231 | || (p.exactStart && p.hostParts.length !== u.hostParts.length) |
| 232 | || (p.exactEnd && p.pathParts.length !== u.pathParts.length) |
| 233 | || (p.port !== '*' && p.port !== u.port) |
| 234 | || (p.protocol && p.protocol !== u.protocol) |
| 235 | ) { |
| 236 | return false; |
| 237 | } |
| 238 | |
| 239 | for (let i = 0; i < p.hostParts.length; i++) { |
| 240 | const pHostPart = p.hostParts[i]; |
| 241 | const uHostPart = u.hostParts[i]; |
| 242 | if (pHostPart !== '*' && pHostPart !== uHostPart) { |
| 243 | return false; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | if ( |
| 248 | p.hostParts.length >= 2 |
| 249 | && p.hostParts.at(-1) !== '*' |
| 250 | && ( |
| 251 | p.hostParts.length < u.hostParts.length - 1 |
| 252 | || ( |
| 253 | p.hostParts.length === u.hostParts.length - 1 |
| 254 | && u.hostParts.at(-1) !== 'www' |
| 255 | ) |
| 256 | ) |
| 257 | ) { |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | if (p.pathParts.length === 0) { |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | if (p.pathParts.length > u.pathParts.length) { |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | for (let i = 0; i < p.pathParts.length; i++) { |
| 270 | const pPathPart = p.pathParts[i]; |
| 271 | const uPathPart = u.pathParts[i]; |
| 272 | if (pPathPart !== '*' && pPathPart !== uPathPart) { |
| 273 | return false; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | return true; |
| 278 | } |
| 279 | |
| 280 | function isRegExp(pattern: string) { |
| 281 | return pattern.startsWith('/') && pattern.endsWith('/') && pattern.length > 2; |
no outgoing calls
no test coverage detected