mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	This commit asserts that parse_user_agent never returns None. The RegEx will match any string, so that `match` is never None. This brings test coverage of lib/user_agent.py to 100%. Changes were also made in test/test_decorators.py and views/compatibility.py to reflect that parse_user_agent cannot return None. Improves: #7089. Fixes: #8779.
		
			
				
	
	
		
			11 lines
		
	
	
		
			411 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			11 lines
		
	
	
		
			411 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import re
 | 
						|
from typing import Dict
 | 
						|
 | 
						|
# Warning: If you change this parsing, please test using
 | 
						|
#   zerver/tests/test_decorators.py
 | 
						|
# And extend zerver/fixtures/user_agents_unique with any new test cases
 | 
						|
def parse_user_agent(user_agent: str) -> Dict[str, str]:
 | 
						|
    match = re.match("^(?P<name>[^/ ]*[^0-9/(]*)(/(?P<version>[^/ ]*))?([ /].*)?$", user_agent)
 | 
						|
    assert match is not None
 | 
						|
    return match.groupdict()
 |