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

Skip to content

Commit 33c2bdf

Browse files
committed
Merge pull request ua-parser#22 from kevinlondon/master
Switch from yaml.load to yaml.safe_load for security
2 parents 9078a89 + 9f68bc8 commit 33c2bdf

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def install_regexes():
2020
import json
2121
import yaml
2222
json_dest = yaml_dest.replace('.yaml', '.json')
23-
regexes = yaml.load(open(yaml_dest))
23+
regexes = yaml.safe_load(open(yaml_dest))
2424
with open(json_dest, "w") as f:
2525
json.dump(regexes, f)
2626

ua_parser/user_agent_parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _repl(m):
169169
if index < len(group):
170170
return group[index]
171171
return ''
172-
172+
173173
_string = re.sub(r'\$(\d)', _repl, string)
174174
_string = re.sub(r'^\s+|\s+$', '', _string)
175175
if _string == '':
@@ -179,7 +179,7 @@ def _repl(m):
179179
def Parse(self, user_agent_string):
180180
device, brand, model = None, None, None
181181
match = self.user_agent_re.search(user_agent_string)
182-
if match:
182+
if match:
183183
if self.device_replacement:
184184
device = self.MultiReplace(self.device_replacement, match)
185185
else:
@@ -442,9 +442,9 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
442442
else:
443443
import yaml
444444

445-
yamlFile = open(UA_PARSER_YAML)
446-
regexes = yaml.load(yamlFile)
447-
yamlFile.close()
445+
with open(UA_PARSER_YAML) as yamlFile:
446+
regexes = yaml.safe_load(yamlFile)
447+
448448

449449
# If UA_PARSER_YAML is not specified, load regexes from regexes.json before
450450
# falling back to yaml format
@@ -458,7 +458,7 @@ def GetFilters(user_agent_string, js_user_agent_string=None,
458458
import yaml
459459

460460
with open(yamlPath) as fp:
461-
regexes = yaml.load(fp)
461+
regexes = yaml.safe_load(fp)
462462

463463

464464
USER_AGENT_PARSERS = []

0 commit comments

Comments
 (0)