Repository navigation
Commit 1e3fabe
committed
fix(azure/reservations): repair progressive-drop loop in BuildDisplayName
Address CodeRabbit findings on PR #686.
Critical: BuildDisplayName's progressive-drop loop was broken. It called
SanitizeDisplayName(candidate) inside the loop before checking the
length cap. Because the sanitizer hard-truncates to 64 chars, the
condition len(candidate) <= 64 was vacuously true on iteration 1 and
the loop exited immediately, returning a mid-string-truncated full
format instead of cleanly dropping the random suffix, timestamp, and
payment segments. The existing tests passed only by coincidence (all
test inputs happened to land their required segments within the first
64 bytes of the full format).
Fix: check the pre-sanitized length to gate segment-dropping, and
sanitize only on the exit path. Each segment is already conformant via
normalizeSegment, so the in-loop sanitization was both wrong and
redundant.
Add three regression tests that fail against the pre-fix code:
- DropLoopActuallyDropsTimestamp: forces the loop to drop both random
and timestamp; asserts the exact clean output and that no timestamp
digits leak in.
- DropLoopActuallyDropsPayment: forces required-only fallback; asserts
no payment fragment survives.
- ZeroNowReplacedByWallClock: asserts a zero-value Now is replaced by
time.Now() rather than emitting the placeholder "00010101T000000".
Also address three minor doc/safety findings on the same file:
- Clarify isAllowedDisplayNameChar godoc so the [A-Za-z0-9-] description
matches reality (underscores are passed through by the caller).
- Guard the zero-value Now case so production callers that forget to
set it get a real timestamp instead of "00010101T000000".
- Document generateRandSuffix's silent fallback for non-nil src shorter
than 4 bytes.
Verification: stash-revert the production code change with the new
tests in place; all three regression tests fail with exactly the
expected mid-truncated outputs. Restore the fix; all 68 reservations
tests pass and all 620 azure-package tests pass.1 parent 8add0cb commit 1e3fabe
2 files changed
Lines changed: 109 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
79 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
80 | 84 | | |
81 | 85 | | |
82 | 86 | | |
| |||
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
117 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
118 | 129 | | |
119 | 130 | | |
120 | 131 | | |
| |||
124 | 135 | | |
125 | 136 | | |
126 | 137 | | |
127 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
128 | 144 | | |
129 | 145 | | |
130 | 146 | | |
131 | 147 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | 148 | | |
137 | | - | |
| 149 | + | |
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| |||
206 | 218 | | |
207 | 219 | | |
208 | 220 | | |
209 | | - | |
210 | | - | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 | | |
212 | 227 | | |
213 | 228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
412 | 493 | | |
413 | 494 | | |
414 | 495 | | |
| |||
0 commit comments