File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Bug Fix for Issue #5000
2+ import re
3+ from typing import Tuple , Optional
4+
5+ def validate_input (input_data : str ) -> Tuple [bool , str ]:
6+ if not input_data :
7+ return False , "Input cannot be empty"
8+ if len (input_data ) > 1000 :
9+ return False , "Input too long"
10+ return True , "OK"
11+
12+ def sanitize_output (output_data : str ) -> str :
13+ if not output_data :
14+ return ""
15+ # 移除XSS风险字符
16+ dangerous = ['<script' , 'javascript:' , 'onerror=' , 'onload=' ]
17+ for d in dangerous :
18+ if d .lower () in output_data .lower ():
19+ output_data = re .sub (d , '' , output_data , flags = re .IGNORECASE )
20+ return output_data .strip ()
21+
22+ # 测试
23+ assert validate_input ("test" )[0 ] == True
24+ assert validate_input ("" )[0 ] == False
25+ assert sanitize_output ("test" ) == "test"
26+ assert "<script" not in sanitize_output ("test<script>" )
27+ print ("Bug fix tests passed!" )
You can’t perform that action at this time.
0 commit comments