@@ -2452,6 +2452,40 @@ class Root(BaseModel):
2452
2452
)
2453
2453
2454
2454
2455
+ def test_cli_with_unbalanced_brackets_in_json_string ():
2456
+ class StrToStrDictOptions (BaseSettings ):
2457
+ nested : dict [str , str ]
2458
+
2459
+ assert CliApp .run (StrToStrDictOptions , cli_args = ['--nested={"test": "{"}' ]).model_dump () == {
2460
+ 'nested' : {'test' : '{' }
2461
+ }
2462
+ assert CliApp .run (StrToStrDictOptions , cli_args = ['--nested={"test": "}"}' ]).model_dump () == {
2463
+ 'nested' : {'test' : '}' }
2464
+ }
2465
+ assert CliApp .run (StrToStrDictOptions , cli_args = ['--nested={"test": "["}' ]).model_dump () == {
2466
+ 'nested' : {'test' : '[' }
2467
+ }
2468
+ assert CliApp .run (StrToStrDictOptions , cli_args = ['--nested={"test": "]"}' ]).model_dump () == {
2469
+ 'nested' : {'test' : ']' }
2470
+ }
2471
+
2472
+ class StrToListDictOptions (BaseSettings ):
2473
+ nested : dict [str , list [str ]]
2474
+
2475
+ assert CliApp .run (StrToListDictOptions , cli_args = ['--nested={"test": ["{"]}' ]).model_dump () == {
2476
+ 'nested' : {'test' : ['{' ]}
2477
+ }
2478
+ assert CliApp .run (StrToListDictOptions , cli_args = ['--nested={"test": ["}"]}' ]).model_dump () == {
2479
+ 'nested' : {'test' : ['}' ]}
2480
+ }
2481
+ assert CliApp .run (StrToListDictOptions , cli_args = ['--nested={"test": ["["]}' ]).model_dump () == {
2482
+ 'nested' : {'test' : ['[' ]}
2483
+ }
2484
+ assert CliApp .run (StrToListDictOptions , cli_args = ['--nested={"test": ["]"]}' ]).model_dump () == {
2485
+ 'nested' : {'test' : [']' ]}
2486
+ }
2487
+
2488
+
2455
2489
def test_cli_json_optional_default ():
2456
2490
class Nested (BaseModel ):
2457
2491
foo : int = 1
0 commit comments