-
-
Notifications
You must be signed in to change notification settings - Fork 5
fix: cap unwrap depth in timeout normalization #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a8d97e6
chore: syncing versions and shrinkwrap
nevware21-bot 7260791
fix: cap unwrap depth in timeout normalization
nev21 87fb53d
Merge 7260791c6440ea4e4dadc0ae73fa5fe2ae0f9885 into c133f5ae325b23279…
nev21 b4fd64b
Merge remote-tracking branch 'origin/main' into nev21/NormalizeTimeout
nevware21-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * @nevware21/ts-async | ||
| * https://github.com/nevware21/ts-async | ||
| * | ||
| * Copyright (c) 2026 NevWare21 Solutions LLC | ||
| * Licensed under the MIT license. | ||
| */ | ||
|
|
||
| import { assert } from "@nevware21/tripwire"; | ||
| import { _normalizeTimeoutValue } from "../../../src/internal/timeout_helpers"; | ||
|
|
||
| describe("_normalizeTimeoutValue", () => { | ||
| it("should return the default when timeout is undefined", () => { | ||
| assert.strictEqual(_normalizeTimeoutValue(undefined, 42), 42); | ||
| assert.strictEqual(_normalizeTimeoutValue(undefined, undefined), undefined); | ||
| }); | ||
|
|
||
| it("should return the numeric timeout directly", () => { | ||
| assert.strictEqual(_normalizeTimeoutValue(100, 42), 100); | ||
| assert.strictEqual(_normalizeTimeoutValue(0, 42), 0); | ||
| }); | ||
|
|
||
| it("should unwrap a single-nested array to find the numeric timeout", () => { | ||
| assert.strictEqual(_normalizeTimeoutValue([10], 42), 10); | ||
| }); | ||
|
|
||
| it("should unwrap several levels of nested arrays", () => { | ||
| assert.strictEqual(_normalizeTimeoutValue([[[10]]], 42), 10); | ||
| }); | ||
|
|
||
| it("should fall back to the default when the array holds no numeric value", () => { | ||
| assert.strictEqual(_normalizeTimeoutValue([], 42), 42); | ||
| assert.strictEqual(_normalizeTimeoutValue([undefined], 42), 42); | ||
| assert.strictEqual(_normalizeTimeoutValue(["not-a-number"], 42), 42); | ||
| }); | ||
|
|
||
| it("should fall back to the default once the unwrap depth cap is exceeded", () => { | ||
| // Nested 6 levels deep - one more than the 5 iteration cap - so no numeric value is ever found. | ||
| let deeplyNested: any = 10; | ||
| for (let i = 0; i < 6; i++) { | ||
| deeplyNested = [deeplyNested]; | ||
| } | ||
|
|
||
| assert.strictEqual(_normalizeTimeoutValue(deeplyNested, 42), 42); | ||
| }); | ||
|
|
||
| it("should still find the numeric value when nested exactly at the depth cap", () => { | ||
| let nested: any = 10; | ||
| for (let i = 0; i < 5; i++) { | ||
| nested = [nested]; | ||
| } | ||
|
|
||
| assert.strictEqual(_normalizeTimeoutValue(nested, 42), 10); | ||
| }); | ||
|
|
||
| it("should not hang or overflow the stack for a self-referential array", () => { | ||
| let selfRef: any[] = []; | ||
| selfRef[0] = selfRef; | ||
|
|
||
| let start = Date.now(); | ||
| assert.strictEqual(_normalizeTimeoutValue(selfRef, 42), 42); | ||
| assert.isTrue((Date.now() - start) < 1200, "Should return promptly rather than looping forever"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.