File size: 1,181 Bytes
447ebeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Test URL encoding handling for emails with + characters
import re
from urllib.parse import unquote

def test_user_id_parsing():
    # Simulate the raw query string that would come from the URL
    # When user calls: http://0.0.0.0:4000/user/[email protected]
    # The query string would be: [email protected]
    
    test_cases = [
        "[email protected]",
        "user_id=machine-user%[email protected]",  # URL encoded +
        "[email protected]",
        "[email protected]&other_param=value"
    ]
    
    for query_string in test_cases:
        print(f"\nTesting query string: {query_string}")
        
        if 'user_id=' in query_string:
            match = re.search(r'user_id=([^&]*)', query_string)
            if match:
                raw_user_id = unquote(match.group(1))
                print(f"Extracted user_id: {raw_user_id}")
            else:
                print("No match found")
        else:
            print("user_id not found in query string")

if __name__ == "__main__":
    test_user_id_parsing()