Skip to content

Commit 86ecef6

Browse files
authored
Merge pull request #19144 from jketema/dollar-escape
C++: Escape any `$` - specifically in `$@` - coming from error messages
2 parents 0c74f21 + 8dbd81b commit 86ecef6

File tree

6 files changed

+13
-5
lines changed

6 files changed

+13
-5
lines changed

cpp/ql/src/Diagnostics/ExtractionWarnings.ql

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ where
1414
or
1515
warning instanceof ExtractionUnknownProblem
1616
select warning,
17-
"Extraction failed in " + warning.getFile() + " with warning " + warning.getProblemMessage(),
18-
warning.getSeverity()
17+
"Extraction failed in " + warning.getFile() + " with warning " +
18+
warning.getProblemMessage().replaceAll("$", "$$"), warning.getSeverity()

cpp/ql/src/Diagnostics/Internal/ExtractionErrors.ql

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ from ExtractionError error
1717
where
1818
error instanceof ExtractionUnknownError or
1919
exists(error.getFile().getRelativePath())
20-
select error, "Extraction failed in " + error.getFile() + " with error " + error.getErrorMessage(),
21-
error.getSeverity()
20+
select error,
21+
"Extraction failed in " + error.getFile() + " with error " +
22+
error.getErrorMessage().replaceAll("$", "$$"), error.getSeverity()
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
| containserror.cpp:9:14:9:14 | Recoverable extraction error: 'x' has already been declared in the current scope | Extraction failed in containserror.cpp with error "containserror.cpp", line 9: error: "x" has already been declared in the current scope\n \tconst char *x = "Foo2 $$@ bar2 $$@ baz2";\n \t ^\n\n | 2 |
12
| doesnotcompile.cpp:4:2:4:2 | Recoverable extraction error: identifier 'This' is undefined | Extraction failed in doesnotcompile.cpp with error "doesnotcompile.cpp", line 4: error: identifier "This" is undefined\n \tThis is not correct C/C++ code.\n \t^\n\n | 2 |
23
| doesnotcompile.cpp:4:10:4:10 | Recoverable extraction error: expected a ';' | Extraction failed in doesnotcompile.cpp with error "doesnotcompile.cpp", line 4: error: expected a ";"\n \tThis is not correct C/C++ code.\n \t ^\n\n | 2 |
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
| containserror.cpp:9:14:9:14 | Recoverable extraction error: 'x' has already been declared in the current scope | Extraction failed in containserror.cpp with warning "containserror.cpp", line 9: error: "x" has already been declared in the current scope\n \tconst char *x = "Foo2 $$@ bar2 $$@ baz2";\n \t ^\n\n | 1 |
12
| doesnotcompile.cpp:4:2:4:2 | Recoverable extraction error: identifier 'This' is undefined | Extraction failed in doesnotcompile.cpp with warning "doesnotcompile.cpp", line 4: error: identifier "This" is undefined\n \tThis is not correct C/C++ code.\n \t^\n\n | 1 |
23
| doesnotcompile.cpp:4:10:4:10 | Recoverable extraction error: expected a ';' | Extraction failed in doesnotcompile.cpp with warning "doesnotcompile.cpp", line 4: error: expected a ";"\n \tThis is not correct C/C++ code.\n \t ^\n\n | 1 |

cpp/ql/test/query-tests/Diagnostics/Info.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| containserror.cpp:0:0:0:0 | containserror.cpp | containserror.cpp | fromSource, normalTermination |
1+
| containserror.cpp:0:0:0:0 | containserror.cpp | containserror.cpp | ExtractionProblem (severity 1), fromSource, normalTermination |
22
| containswarning.cpp:0:0:0:0 | containswarning.cpp | containswarning.cpp | fromSource, normalTermination |
33
| doesnotcompile.cpp:0:0:0:0 | doesnotcompile.cpp | doesnotcompile.cpp | ExtractionProblem (severity 1), fromSource, normalTermination |
44
| file://:0:0:0:0 | | | |

cpp/ql/test/query-tests/Diagnostics/containserror.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
void containserror() {
44
#error An error!
55
}
6+
7+
void error_with_placeholder() {
8+
const char *x = "Foo1 $@ bar1 $@ baz1";
9+
const char *x = "Foo2 $@ bar2 $@ baz2";
10+
}

0 commit comments

Comments
 (0)