Skip to content

Commit 7be070f

Browse files
feat(core): escape double colons in type URI bench arguments
1 parent 4f381d3 commit 7be070f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

core/src/codspeed.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
#include <string>
55
#include <vector>
66

7+
std::string searchAndReplaceBetweenBrackets(std::string &text,
8+
const std::string &search,
9+
const std::string &replace) {
10+
// Check if the string ends with ']'
11+
if (text.back() == ']') {
12+
// Find the rightmost '['
13+
size_t posOpen = text.rfind('[');
14+
if (posOpen != std::string::npos) {
15+
// Extract the substring between '[' and ']'
16+
size_t posClose = text.size() - 1;
17+
std::string substring = text.substr(posOpen + 1, posClose - posOpen - 1);
18+
19+
// Perform the search and replace within the substring
20+
size_t pos = substring.find(search);
21+
while (pos != std::string::npos) {
22+
substring.replace(pos, search.length(), replace);
23+
pos = substring.find(search, pos + replace.length());
24+
}
25+
26+
// Replace the original substring with the modified one
27+
text.replace(posOpen + 1, posClose - posOpen - 1, substring);
28+
}
29+
}
30+
return text;
31+
}
32+
733
std::string join(const std::vector<std::string> &elements,
834
const std::string &delimiter) {
935
std::string result;
@@ -40,6 +66,11 @@ void CodSpeed::pop_group() {
4066
void CodSpeed::start_benchmark(const std::string &name) {
4167
std::string uri = name;
4268

69+
// Remove any `::` between brackets at the end to not mess with the URI
70+
// parsing
71+
// FIXME: Remove this bandaid when we migrate to structured benchmark metadata
72+
uri = searchAndReplaceBetweenBrackets(uri, "::", "\\:\\:");
73+
4374
// Sanity check URI and add a placeholder if format is wrong
4475
if (name.find("::") == std::string::npos) {
4576
std::string uri = "unknown_file::" + name;

0 commit comments

Comments
 (0)