mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-25 01:59:52 +08:00
fix: escape 5065 in variable value
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
- fix: incorrect summary success when testcase failed
|
- fix: incorrect summary success when testcase failed
|
||||||
- fix: reload to refresh previously loaded debugtalk module
|
- fix: reload to refresh previously loaded debugtalk module
|
||||||
|
- fix: escape $$ in variable value
|
||||||
|
|
||||||
## 3.0.10 (2020-06-07)
|
## 3.0.10 (2020-06-07)
|
||||||
|
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ def build_url(base_url, path):
|
|||||||
raise exceptions.ParamsError("base url missed!")
|
raise exceptions.ParamsError("base url missed!")
|
||||||
|
|
||||||
|
|
||||||
def regex_findall_variables(content: Text) -> List[Text]:
|
def regex_findall_variables(raw_string: Text) -> List[Text]:
|
||||||
""" extract all variable names from content, which is in format $variable
|
""" extract all variable names from content, which is in format $variable
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
content (str): string content
|
raw_string (str): string content
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: variables list extracted from string content
|
list: variables list extracted from string content
|
||||||
@@ -68,14 +68,40 @@ def regex_findall_variables(content: Text) -> List[Text]:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
vars_list = []
|
match_start_position = raw_string.index("$", 0)
|
||||||
for var_tuple in variable_regex_compile.findall(content):
|
except ValueError:
|
||||||
vars_list.append(var_tuple[0] or var_tuple[1])
|
|
||||||
return vars_list
|
|
||||||
except TypeError as ex:
|
|
||||||
capture_exception(ex)
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
vars_list = []
|
||||||
|
while match_start_position < len(raw_string):
|
||||||
|
|
||||||
|
# Notice: notation priority
|
||||||
|
# $$ > $var
|
||||||
|
|
||||||
|
# search $$
|
||||||
|
dollar_match = dolloar_regex_compile.match(raw_string, match_start_position)
|
||||||
|
if dollar_match:
|
||||||
|
match_start_position = dollar_match.end()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# search variable like ${var} or $var
|
||||||
|
var_match = variable_regex_compile.match(raw_string, match_start_position)
|
||||||
|
if var_match:
|
||||||
|
var_name = var_match.group(1) or var_match.group(2)
|
||||||
|
vars_list.append(var_name)
|
||||||
|
match_start_position = var_match.end()
|
||||||
|
continue
|
||||||
|
|
||||||
|
curr_position = match_start_position
|
||||||
|
try:
|
||||||
|
# find next $ location
|
||||||
|
match_start_position = raw_string.index("$", curr_position + 1)
|
||||||
|
except ValueError:
|
||||||
|
# break while loop
|
||||||
|
break
|
||||||
|
|
||||||
|
return vars_list
|
||||||
|
|
||||||
|
|
||||||
def regex_findall_functions(content: Text) -> List[Text]:
|
def regex_findall_functions(content: Text) -> List[Text]:
|
||||||
""" extract all functions from string content, which are in format ${fun()}
|
""" extract all functions from string content, which are in format ${fun()}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import unittest
|
|||||||
|
|
||||||
from httprunner import parser
|
from httprunner import parser
|
||||||
from httprunner.exceptions import VariableNotFound, FunctionNotFound
|
from httprunner.exceptions import VariableNotFound, FunctionNotFound
|
||||||
|
from httprunner.parser import regex_findall_variables
|
||||||
|
|
||||||
|
|
||||||
class TestParserBasic(unittest.TestCase):
|
class TestParserBasic(unittest.TestCase):
|
||||||
@@ -25,6 +26,19 @@ class TestParserBasic(unittest.TestCase):
|
|||||||
self.assertEqual(parser.parse_string_value("$var"), "$var")
|
self.assertEqual(parser.parse_string_value("$var"), "$var")
|
||||||
self.assertEqual(parser.parse_string_value("${func}"), "${func}")
|
self.assertEqual(parser.parse_string_value("${func}"), "${func}")
|
||||||
|
|
||||||
|
def test_regex_findall_variables(self):
|
||||||
|
self.assertEqual(regex_findall_variables("$variable"), ["variable"])
|
||||||
|
self.assertEqual(regex_findall_variables("${variable}123"), ["variable"])
|
||||||
|
self.assertEqual(regex_findall_variables("/blog/$postid"), ["postid"])
|
||||||
|
self.assertEqual(regex_findall_variables("/$var1/$var2"), ["var1", "var2"])
|
||||||
|
self.assertEqual(regex_findall_variables("abc"), [])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$a"), ["a"])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$$a"), [])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$$$a"), ["a"])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$$$$a"), [])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$$a$b"), ["b"])
|
||||||
|
self.assertEqual(regex_findall_variables("Z:2>1*0*1+1$$a$$b"), [])
|
||||||
|
|
||||||
def test_extract_variables(self):
|
def test_extract_variables(self):
|
||||||
self.assertEqual(parser.extract_variables("$var"), {"var"})
|
self.assertEqual(parser.extract_variables("$var"), {"var"})
|
||||||
self.assertEqual(parser.extract_variables("$var123"), {"var123"})
|
self.assertEqual(parser.extract_variables("$var123"), {"var123"})
|
||||||
@@ -40,6 +54,7 @@ class TestParserBasic(unittest.TestCase):
|
|||||||
parser.extract_variables("${gen_md5($TOKEN, $data, $random)}"),
|
parser.extract_variables("${gen_md5($TOKEN, $data, $random)}"),
|
||||||
{"TOKEN", "data", "random"},
|
{"TOKEN", "data", "random"},
|
||||||
)
|
)
|
||||||
|
self.assertEqual(parser.extract_variables("Z:2>1*0*1+1$$1"), set())
|
||||||
|
|
||||||
def test_parse_function_params(self):
|
def test_parse_function_params(self):
|
||||||
self.assertEqual(parser.parse_function_params(""), {"args": [], "kwargs": {}})
|
self.assertEqual(parser.parse_function_params(""), {"args": [], "kwargs": {}})
|
||||||
|
|||||||
Reference in New Issue
Block a user