( segment: string, label: string, )
| 96 | } |
| 97 | |
| 98 | function normalizeGeneratedFilePathSegment( |
| 99 | segment: string, |
| 100 | label: string, |
| 101 | ): string { |
| 102 | if (segment.length === 0) return segment; |
| 103 | |
| 104 | const startsWithControl = |
| 105 | STARTS_WITH_CONTROL_OR_LINE_SEPARATOR.test(segment); |
| 106 | const endsWithControl = ENDS_WITH_CONTROL_OR_LINE_SEPARATOR.test(segment); |
| 107 | let normalized = collapseControlRunsWithSpaces(segment); |
| 108 | |
| 109 | if (startsWithControl) normalized = normalized.replace(/^ /u, ""); |
| 110 | if (endsWithControl) normalized = normalized.replace(/ $/u, ""); |
| 111 | |
| 112 | const withoutTrailingSpaces = trimTrailingCharsLinear(normalized, " "); |
| 113 | if (withoutTrailingSpaces === "." || withoutTrailingSpaces === "..") { |
| 114 | throw new Error(`${label} cannot contain "." or ".." path segments.`); |
| 115 | } |
| 116 | |
| 117 | normalized = trimTrailingCharsLinear(normalized, ". "); |
| 118 | |
| 119 | if (!normalized) { |
| 120 | throw new Error(`${label} contains an empty path segment after formatting.`); |
| 121 | } |
| 122 | |
| 123 | return normalized; |
| 124 | } |
no test coverage detected