Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e8fc93

Browse files
author
Sergey Polischouck
committed
fix os parsing specification with replacing
1 parent 75b7d33 commit 6e8fc93

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ua_parser/user_agent_parser.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,26 @@ def Parse(self, user_agent_string):
125125
os_v1 = match.group(2)
126126

127127
if self.os_v2_replacement:
128-
os_v2 = self.os_v2_replacement
128+
if re.search(r'\$2', self.os_v2_replacement):
129+
os_v2 = re.sub(r'\$2', match.group(2), self.os_v2_replacement)
130+
else:
131+
os_v2 = self.os_v2_replacement
129132
elif match.lastindex and match.lastindex >= 3:
130133
os_v2 = match.group(3)
131134

132135
if self.os_v3_replacement:
133-
os_v3 = self.os_v3_replacement
136+
if re.search(r'\$3', self.os_v3_replacement):
137+
os_v3 = re.sub(r'\$3', match.group(3), self.os_v3_replacement)
138+
else:
139+
os_v3 = self.os_v3_replacement
134140
elif match.lastindex and match.lastindex >= 4:
135141
os_v3 = match.group(4)
136142

137143
if self.os_v4_replacement:
138-
os_v4 = self.os_v4_replacement
144+
if re.search(r'\$4', self.os_v4_replacement):
145+
os_v4 = re.sub(r'\$4', match.group(4), self.os_v4_replacement)
146+
else:
147+
os_v4 = self.os_v4_replacement
139148
elif match.lastindex and match.lastindex >= 5:
140149
os_v4 = match.group(5)
141150

0 commit comments

Comments
 (0)