mirror of
https://github.com/httprunner/httprunner.git
synced 2026-08-28 03:30:01 +08:00
fix #1103: variable should not start with digit
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
## 3.1.8 (2022-03-22)
|
## 3.1.8 (2022-03-22)
|
||||||
|
|
||||||
|
- feat: add `--profile` flag for har2case to support overwrite headers/cookies with specified yaml/json configuration file
|
||||||
|
- feat: support variable and function in response extract expression
|
||||||
- fix: keep negative index in jmespath unchanged when converting pytest files, e.g. body.users[-1]
|
- fix: keep negative index in jmespath unchanged when converting pytest files, e.g. body.users[-1]
|
||||||
|
- fix: variable should not start with digit
|
||||||
- change: load yaml file with FullLoader
|
- change: load yaml file with FullLoader
|
||||||
|
|
||||||
## 3.1.7 (2022-03-22)
|
## 3.1.7 (2022-03-22)
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ absolute_http_url_regexp = re.compile(r"^https?://", re.I)
|
|||||||
# use $$ to escape $ notation
|
# use $$ to escape $ notation
|
||||||
dolloar_regex_compile = re.compile(r"\$\$")
|
dolloar_regex_compile = re.compile(r"\$\$")
|
||||||
# variable notation, e.g. ${var} or $var
|
# variable notation, e.g. ${var} or $var
|
||||||
variable_regex_compile = re.compile(r"\$\{(\w+)\}|\$(\w+)")
|
# variable should start with a-zA-Z_
|
||||||
|
variable_regex_compile = re.compile(r"\$\{([a-zA-Z_]\w*)\}|\$([a-zA-Z_]\w*)")
|
||||||
# function notation, e.g. ${func1($var_1, $var_3)}
|
# function notation, e.g. ${func1($var_1, $var_3)}
|
||||||
function_regex_compile = re.compile(r"\$\{(\w+)\(([\$\w\.\-/\s=,]*)\)\}")
|
function_regex_compile = re.compile(r"\$\{([a-zA-Z_]\w*)\(([\$\w\.\-/\s=,]*)\)\}")
|
||||||
|
|
||||||
|
|
||||||
def parse_string_value(str_value: Text) -> Any:
|
def parse_string_value(str_value: Text) -> Any:
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ class TestParserBasic(unittest.TestCase):
|
|||||||
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$$$a"), [])
|
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$$$a"), [])
|
||||||
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$a$b"), ["b"])
|
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$a$b"), ["b"])
|
||||||
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$a$$b"), [])
|
self.assertEqual(parser.regex_findall_variables("Z:2>1*0*1+1$$a$$b"), [])
|
||||||
|
# variable should not start with digit
|
||||||
|
self.assertEqual(parser.regex_findall_variables("$1a"), [])
|
||||||
|
self.assertEqual(parser.regex_findall_variables("${1a}"), [])
|
||||||
|
|
||||||
def test_extract_variables(self):
|
def test_extract_variables(self):
|
||||||
self.assertEqual(parser.extract_variables("$var"), {"var"})
|
self.assertEqual(parser.extract_variables("$var"), {"var"})
|
||||||
@@ -230,7 +233,8 @@ class TestParserBasic(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_parse_data_string_with_functions(self):
|
def test_parse_data_string_with_functions(self):
|
||||||
import random, string
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
functions_mapping = {
|
functions_mapping = {
|
||||||
"gen_random_string": lambda str_len: "".join(
|
"gen_random_string": lambda str_len: "".join(
|
||||||
@@ -243,8 +247,7 @@ class TestParserBasic(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(len(result), 5)
|
self.assertEqual(len(result), 5)
|
||||||
|
|
||||||
add_two_nums = lambda a, b=1: a + b
|
functions_mapping["add_two_nums"] = lambda a, b=1: a + b
|
||||||
functions_mapping["add_two_nums"] = add_two_nums
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
parser.parse_data(
|
parser.parse_data(
|
||||||
"${add_two_nums(1)}", functions_mapping=functions_mapping
|
"${add_two_nums(1)}", functions_mapping=functions_mapping
|
||||||
|
|||||||
Reference in New Issue
Block a user