File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1- from hyperbrowser .type_utils import is_plain_string
1+ from hyperbrowser .type_utils import is_plain_int , is_plain_string
22
33_TRUNCATED_DISPLAY_SUFFIX = "... (truncated)"
44_DEFAULT_BLANK_KEY_FALLBACK = "<blank key>"
5+ _DEFAULT_MAX_DISPLAY_LENGTH = 200
56
67
78def normalize_display_text (value : object , * , max_length : int ) -> str :
89 if not is_plain_string (value ):
910 return ""
11+ if not is_plain_int (max_length ) or max_length <= 0 :
12+ max_length = _DEFAULT_MAX_DISPLAY_LENGTH
1013 try :
1114 sanitized_value = "" .join (
1215 "?" if ord (character ) < 32 or ord (character ) == 127 else character
Original file line number Diff line number Diff line change @@ -37,6 +37,15 @@ class _StringSubclass(str):
3737 assert normalize_display_text (_StringSubclass ("value" ), max_length = 20 ) == ""
3838
3939
40+ def test_normalize_display_text_uses_default_length_for_non_int_max_length ():
41+ assert normalize_display_text ("value" , max_length = "invalid" ) == "value" # type: ignore[arg-type]
42+
43+
44+ def test_normalize_display_text_uses_default_length_for_non_positive_max_length ():
45+ assert normalize_display_text ("value" , max_length = 0 ) == "value"
46+ assert normalize_display_text ("value" , max_length = - 10 ) == "value"
47+
48+
4049def test_format_string_key_for_error_returns_normalized_key ():
4150 assert format_string_key_for_error (" \n key\t " , max_length = 20 ) == "?key?"
4251
You can’t perform that action at this time.
0 commit comments