Skip to content

Commit 9e73ecc

Browse files
kakasooclaude
andcommitted
fix: prevent deepStrictAssert crash on non-leaf object keys
Add `rest.length > 0` guard before recursing into nested objects, consistent with the existing fix in `deepStrictPick`. Closes #19. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent edbee31 commit 9e73ecc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/functions/DeepStrictAssert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const deepStrictAssert =
3333
if (input instanceof Array) {
3434
const elements = input.map((element) => {
3535
if (first in element) {
36-
if (typeof element[first] === 'object' && element[first] !== null) {
36+
if (typeof element[first] === 'object' && element[first] !== null && rest.length > 0) {
3737
return { [first]: traverse(element[first], rest) };
3838
}
3939

@@ -46,7 +46,7 @@ export const deepStrictAssert =
4646
return elements;
4747
} else {
4848
if (first in input) {
49-
if (typeof input[first] === 'object' && input[first] !== null) {
49+
if (typeof input[first] === 'object' && input[first] !== null && rest.length > 0) {
5050
return { [first]: traverse(input[first], rest) };
5151
}
5252
return { [first]: input[first] };

test/features/DeepStrictAssert.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ok } from 'assert';
12
import typia, { tags } from 'typia';
23
import { deepStrictAssert } from '../../src';
34

@@ -130,3 +131,14 @@ export function test_functions_deepStrictAssert_accesses_multiple_nested_array_p
130131
typia.assertEquals(resultD);
131132
typia.assertEquals(resultE);
132133
}
134+
135+
/**
136+
* Tests that deepStrictAssert can access a non-leaf object key without crashing.
137+
* This verifies the fix for GitHub issue #19.
138+
*/
139+
export function test_functions_deepStrictAssert_accesses_non_leaf_object_key() {
140+
const data = { user: { name: 'Alice', age: 30 } };
141+
const result = deepStrictAssert(data)('user');
142+
ok(result.user.name === 'Alice');
143+
ok(result.user.age === 30);
144+
}

0 commit comments

Comments
 (0)