File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -68,7 +68,15 @@ def _validate_operation_name(operation_name: str) -> None:
6868
6969
7070def build_operation_name (prefix : str , identifier : str ) -> str :
71- operation_name = f"{ prefix } { identifier } "
71+ normalized_identifier = identifier .strip ()
72+ if not normalized_identifier :
73+ normalized_identifier = "unknown"
74+ normalized_identifier = "" .join (
75+ "?" if ord (character ) < 32 or ord (character ) == 127 else character
76+ for character in normalized_identifier
77+ )
78+
79+ operation_name = f"{ prefix } { normalized_identifier } "
7280 if len (operation_name ) <= _MAX_OPERATION_NAME_LENGTH :
7381 return operation_name
7482 available_identifier_length = (
Original file line number Diff line number Diff line change @@ -71,6 +71,18 @@ def test_build_operation_name_truncates_overlong_prefixes():
7171 assert operation_name == long_prefix [:200 ]
7272
7373
74+ def test_build_operation_name_sanitizes_identifier_whitespace_and_control_chars ():
75+ operation_name = build_operation_name ("crawl job " , " \n abc\t def\x7f " )
76+
77+ assert operation_name == "crawl job abc?def?"
78+
79+
80+ def test_build_operation_name_uses_unknown_for_blank_identifier ():
81+ operation_name = build_operation_name ("crawl job " , " \n \t " )
82+
83+ assert operation_name == "crawl job unknown"
84+
85+
7486def test_poll_until_terminal_status_allows_immediate_terminal_on_zero_max_wait ():
7587 status = poll_until_terminal_status (
7688 operation_name = "sync immediate zero wait" ,
You can’t perform that action at this time.
0 commit comments