Skip to content

Commit 6a7b505

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

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/src/codspeed.cpp

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

7+
std::string search_and_replace_between_brackets(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 pos_open = text.rfind('[');
14+
if (pos_open != std::string::npos) {
15+
// Extract the substring between '[' and ']'
16+
size_t pos_close = text.size() - 1;
17+
std::string substring =
18+
text.substr(pos_open + 1, pos_close - pos_open - 1);
19+
20+
// Perform the search and replace within the substring
21+
size_t pos = substring.find(search);
22+
while (pos != std::string::npos) {
23+
substring.replace(pos, search.length(), replace);
24+
pos = substring.find(search, pos + replace.length());
25+
}
26+
27+
// Replace the original substring with the modified one
28+
text.replace(pos_open + 1, pos_close - pos_open - 1, substring);
29+
}
30+
}
31+
return text;
32+
}
33+
734
std::string join(const std::vector<std::string> &elements,
835
const std::string &delimiter) {
936
std::string result;
@@ -40,6 +67,11 @@ void CodSpeed::pop_group() {
4067
void CodSpeed::start_benchmark(const std::string &name) {
4168
std::string uri = name;
4269

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

0 commit comments

Comments
 (0)