Skip to content

Commit

Permalink
Escape all strings in re.compile (bugfix) (#1311)
Browse files Browse the repository at this point in the history
* Escape all strings in re.compile

* Additional files
  • Loading branch information
Hook25 authored Jul 18, 2024
1 parent 5b51df1 commit b9a7e6f
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions checkbox-support/checkbox_support/scripts/audio_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
DIRECTIONS = {"source": "input", "sink": "output"}

# use %s string format to compatible with other python version
default_pattern = "(?<=Default %s: ).*"
index_regex = re.compile("(?<=Sink Input #)[0-9]*")
muted_regex = re.compile("(?<=Mute: ).*")
name_regex = re.compile("(?<=Name:).*")
channel_map_regex = re.compile("(?<=Channel Map: ).*")
default_pattern = r"(?<=Default %s: ).*"
index_regex = re.compile(r"(?<=Sink Input #)[0-9]*")
muted_regex = re.compile(r"(?<=Mute: ).*")
name_regex = re.compile(r"(?<=Name:).*")
channel_map_regex = re.compile(r"(?<=Channel Map: ).*")

# use %s string format to compatible with other python version
entry_pattern = "Name: %s.*?(?=Properties)"
entry_pattern = r"Name: %s.*?(?=Properties)"
volume_pattern = r"Volume: .*(?:%s):[\w\/0-9 ]* ([0-9]*)%%"


Expand Down
2 changes: 1 addition & 1 deletion checkbox-support/checkbox_support/scripts/fwts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
)
# By default, we launch all the tests
TESTS = sorted(list(set(QA_TESTS + HWE_TESTS)))
SLEEP_TIME_RE = re.compile("(Suspend|Resume):\s+([\d\.]+)\s+seconds.")
SLEEP_TIME_RE = re.compile(r"(Suspend|Resume):\s+([\d\.]+)\s+seconds.")


def get_sleep_times(log, start_marker):
Expand Down
2 changes: 1 addition & 1 deletion providers/base/bin/battery_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def find_battery():
else:
out, err = batinfo.communicate()
if out:
device_regex = re.compile("Device: (.*battery_.*)")
device_regex = re.compile(r"Device: (.*battery_.*)")
batteries = device_regex.findall(out)
if len(batteries) == 0:
return None
Expand Down
10 changes: 5 additions & 5 deletions providers/base/bin/disk_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def main():
Outputs kernel name, model and size data
"""
pattern = re.compile(
'KNAME="(?P<KNAME>.*)" '
'TYPE="(?P<TYPE>.*)" '
'SIZE="(?P<SIZE>.*)" '
'MODEL="(?P<MODEL>.*)" '
'MOUNTPOINT="(?P<MOUNTPOINT>.*)"'
r'KNAME="(?P<KNAME>.*)" '
r'TYPE="(?P<TYPE>.*)" '
r'SIZE="(?P<SIZE>.*)" '
r'MODEL="(?P<MODEL>.*)" '
r'MOUNTPOINT="(?P<MOUNTPOINT>.*)"'
)
try:
lsblk = check_output(
Expand Down
2 changes: 1 addition & 1 deletion providers/base/bin/frequency_governors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def getCPUFreqDirectories(self):
logging.error("No file %s" % self.sysCPUDirectory)
return None
# look for cpu subdirectories
pattern = re.compile("cpu(?P<cpuNumber>[0-9]+)")
pattern = re.compile(r"cpu(?P<cpuNumber>[0-9]+)")
self.cpufreqDirectories = list()
for subdirectory in os.listdir(self.sysCPUDirectory):
match = pattern.search(subdirectory)
Expand Down
6 changes: 3 additions & 3 deletions providers/base/bin/graphics_stress_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def _print_test_info(self, suites="all", iteration=1, show_errors=False):
temp_file.close()

# Read values from the file
errors = re.compile(".*test error.*")
results = re.compile("(.+) tests passed of (.+) total.*")
errors = re.compile(r".*test error.*")
results = re.compile(r"(.+) tests passed of (.+) total.*")

first_error = True
with open(temp_file.name) as temp_handle:
Expand Down Expand Up @@ -308,7 +308,7 @@ def get_suites_list(self):

proc = process.communicate()[1].split("\n")
found = False
tests_pattern = re.compile(".*Available tests: *(.+).*")
tests_pattern = re.compile(r".*Available tests: *(.+).*")
temp_line = ""
tests = []
for line in proc:
Expand Down
6 changes: 3 additions & 3 deletions providers/base/bin/ipmi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def get_pwr_status(self):
"""
logging.info("-----------------------")
logging.info("Fetching power status:")
regex = re.compile("^System Power")
regex = re.compile(r"^System Power")
try:
output = self._subproc_logging(self._cmd_ipmi_chassis)
for line in output.rstrip().split("\n"):
Expand Down Expand Up @@ -198,7 +198,7 @@ def get_bmc_info(self):

def _ipmi_version_hlpr(self):
"""Ipmi version discovery loop."""
regex = re.compile("^IPMI Version")
regex = re.compile(r"^IPMI Version")
output = self._subproc_logging(self._cmd_get_bmc_info)
for line in output.rstrip().split("\n"):
if re.search(regex, line):
Expand Down Expand Up @@ -245,7 +245,7 @@ def get_ipmi_channel(self):
logging.info("Fetching IPMI channels:")
# support multiple channels
channel = []
regex = re.compile("Section User")
regex = re.compile(r"Section User")
# test channels 0 - 15
for i in range(16):
# channel 12, 13 are invalid channels, skip
Expand Down
2 changes: 1 addition & 1 deletion providers/base/bin/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def run(self):

print("Running ping test...")
result = 0
time_re = re.compile("(?<=time=)[0-9]*")
time_re = re.compile(r"(?<=time=)[0-9]*")
for line in out.decode().split("\n"):
time = time_re.search(line)

Expand Down
10 changes: 5 additions & 5 deletions providers/base/bin/pm_log_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class Parser(object):
r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}"
).search
is_getting_info_line = re.compile(
"Gathering hardware information...$"
r"Gathering hardware information...$"
).search
is_executing_line = re.compile("Executing: '(?P<command>.*)'...$").search
is_output_line = re.compile("Output:$").search
is_executing_line = re.compile(r"Executing: '(?P<command>.*)'...$").search
is_output_line = re.compile(r"Output:$").search
is_field_line = re.compile(
"^- (?P<field>returncode|stdout|stderr):$"
r"^- (?P<field>returncode|stdout|stderr):$"
).match
is_test_complete_line = re.compile("test complete$").search
is_test_complete_line = re.compile(r"test complete$").search

def __init__(self, filename):
self.filename = filename
Expand Down
6 changes: 3 additions & 3 deletions providers/base/bin/removable_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def clean_up(self, target):
def _find_parent(self, device):
if self.lsblk:
pattern = re.compile(
'KNAME="(?P<KNAME>.*)" '
'TYPE="(?P<TYPE>.*)" '
'MOUNTPOINT="(?P<MOUNTPOINT>.*)"'
r'KNAME="(?P<KNAME>.*)" '
r'TYPE="(?P<TYPE>.*)" '
r'MOUNTPOINT="(?P<MOUNTPOINT>.*)"'
)
for line in self.lsblk.splitlines():
m = pattern.match(line)
Expand Down
2 changes: 1 addition & 1 deletion providers/resource/bin/block_device_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from itertools import chain
from subprocess import check_output, CalledProcessError

rootdir_pattern = re.compile("^.*?/devices")
rootdir_pattern = re.compile(r"^.*?/devices")

# NOTE: If raid_types changes, also change it in disk_smart script!
raid_types = ["megaraid", "cciss", "3ware", "areca"]
Expand Down

0 comments on commit b9a7e6f

Please sign in to comment.