Skip to content

Commit acda53a

Browse files
committed
Update for sanitizing regex results and matcher strings.
1 parent d70601e commit acda53a

File tree

43 files changed

+969
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+969
-848
lines changed

regression-tests/pure2-regex_01_char_matcher.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_02_ranges.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_03_wildcard.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_04_start_end.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_05_classes.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_06_boundaries.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_07_short_classes.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_08_alternatives.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_09_groups.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

regression-tests/pure2-regex_10_escapes.cpp2

+14-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
109109
return result;
110110
}
111111

112+
sanitize: (copy str: std::string) -> std::string =
113+
{
114+
str = cpp2::string_util::replace_all(str, "\a", "\\a");
115+
str = cpp2::string_util::replace_all(str, "\f", "\\f");
116+
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
117+
str = cpp2::string_util::replace_all(str, "\n", "\\n");
118+
str = cpp2::string_util::replace_all(str, "\r", "\\r");
119+
str = cpp2::string_util::replace_all(str, "\t", "\\t");
120+
121+
return str;
122+
}
123+
112124
test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
113125
resultExpected: std::string) = {
114126

@@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
131143
result := create_result(resultExpr, r);
132144

133145
if result != resultExpected {
134-
status = "Failure: Result is wrong. (is: (result)$)";
146+
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
135147
}
136148
}
137149
}
@@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
146158
if !warning.empty() {
147159
warning += " ";
148160
}
149-
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
161+
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
150162
}
151163

152164

0 commit comments

Comments
 (0)