Sanitize input content by removing or replacing problematic characters. Args: input_text: The input text to sanitize Returns: str: Sanitized input text
(input_text: str)
| 769 | |
| 770 | |
| 771 | def sanitize_input_content(input_text: str) -> str: |
| 772 | """Sanitize input content by removing or replacing problematic characters. |
| 773 | |
| 774 | Args: |
| 775 | input_text: The input text to sanitize |
| 776 | |
| 777 | Returns: |
| 778 | str: Sanitized input text |
| 779 | """ |
| 780 | # Remove null bytes |
| 781 | text = input_text.replace("\0", "") |
| 782 | |
| 783 | # Replace control characters with spaces (except newlines and tabs) |
| 784 | allowed_chars = {"\n", "\t", "\r"} |
| 785 | sanitized_chars = [] |
| 786 | for c in text: |
| 787 | if c in allowed_chars or ord(c) >= 32: |
| 788 | sanitized_chars.append(c) |
| 789 | else: |
| 790 | sanitized_chars.append(" ") |
| 791 | |
| 792 | # Join characters and normalize whitespace |
| 793 | text = "".join(sanitized_chars) |
| 794 | text = " ".join(text.split()) |
| 795 | |
| 796 | return text |
| 797 | |
| 798 | |
| 799 | def execute_patterns( |
no outgoing calls
no test coverage detected