MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / validate_input_content

Function validate_input_content

scripts/python_ui/streamlit.py:725–769  ·  view source on GitHub ↗

Validate input content for potentially problematic characters or patterns. Args: input_text: The input text to validate Returns: Tuple[bool, str]: (is_valid, error_message)

(input_text: str)

Source from the content-addressed store, hash-verified

723
724
725def validate_input_content(input_text: str) -> Tuple[bool, str]:
726 """Validate input content for potentially problematic characters or patterns.
727
728 Args:
729 input_text: The input text to validate
730
731 Returns:
732 Tuple[bool, str]: (is_valid, error_message)
733 """
734 if not input_text or input_text.isspace():
735 return False, "Input content cannot be empty or only whitespace."
736
737 # Check for minimum length
738 if len(input_text.strip()) < 2:
739 return False, "Input content must be at least 2 characters long."
740
741 # Check for maximum length (e.g., 100KB)
742 if len(input_text.encode("utf-8")) > 100 * 1024:
743 return False, "Input content exceeds maximum size of 100KB."
744
745 # Check for high concentration of special characters
746 special_chars = set("!@#$%^&*()_+[]{}|\\;:'\",.<>?`~")
747 special_char_count = sum(1 for c in input_text if c in special_chars)
748 special_char_ratio = special_char_count / len(input_text)
749
750 if special_char_ratio > 0.3: # More than 30% special characters
751 return (
752 False,
753 "Input contains too many special characters. Please check your input.",
754 )
755
756 # Check for control characters
757 control_chars = set(
758 chr(i) for i in range(32) if i not in [9, 10, 13]
759 ) # Allow tab, newline, carriage return
760 if any(c in control_chars for c in input_text):
761 return False, "Input contains invalid control characters."
762
763 # Check for proper UTF-8 encoding
764 try:
765 input_text.encode("utf-8").decode("utf-8")
766 except UnicodeError:
767 return False, "Input contains invalid Unicode characters."
768
769 return True, ""
770
771
772def sanitize_input_content(input_text: str) -> str:

Callers 2

execute_patternsFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected