(pattern)
| 471 | } |
| 472 | |
| 473 | export function parseTokenRouteRegexPattern(pattern) { |
| 474 | if (!isTokenRouteRegexPattern(pattern)) { |
| 475 | return { regex: null, error: null }; |
| 476 | } |
| 477 | const body = pattern.trim().slice(3).trim(); |
| 478 | if (!body) { |
| 479 | return { regex: null, error: 're: 后缺少正则表达式' }; |
| 480 | } |
| 481 | if (!isSafeRegexPatternBody(body)) { |
| 482 | return { regex: null, error: '出于安全原因不支持该正则表达式' }; |
| 483 | } |
| 484 | try { |
| 485 | return { |
| 486 | regex: compileSafeRegexPattern(body), |
| 487 | error: null, |
| 488 | }; |
| 489 | } catch (error) { |
| 490 | return { regex: null, error: error?.message || '无效正则' }; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | export function matchesTokenRouteModelPattern(model, pattern) { |
| 495 | const normalized = (pattern || '').trim(); |
no test coverage detected