Skip to content

Commit aa1502c

Browse files
committed
Escape special characters
1 parent 4eb6d0c commit aa1502c

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/Properties.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,30 @@ static std::string dropUnsupportedXmlChars(const std::string &input) {
1616
return output;
1717
}
1818

19+
void replace(std::string &input, char c, const char *replacement) {
20+
size_t pos = input.find(c);
21+
while (pos != std::string::npos) {
22+
input.replace(pos, 1, replacement);
23+
pos = input.find(c, pos + 1);
24+
}
25+
}
26+
27+
static std::string escapeSpecialXmlCharacters(const std::string &input) {
28+
std::string output = input;
29+
replace(output, '&', "&");
30+
replace(output, '"', """);
31+
replace(output, '\'', "'");
32+
replace(output, '<', "&lt;");
33+
replace(output, '>', "&gt;");
34+
return output;
35+
}
36+
37+
static std::string sanitize(const std::string &input) {
38+
return escapeSpecialXmlCharacters(dropUnsupportedXmlChars(input));
39+
}
40+
1941
void Properties::setStringProperty(const std::string &key, const std::string &value) {
20-
strings[key] = dropUnsupportedXmlChars(value);
42+
strings[key] = sanitize(value);
2143
}
2244

2345
void Properties::setBooleanProperty(const std::string &key, bool value) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
%0 = type opaque
22

3+
%"struct.std::_Rb_tree<std::__cxx11::basic_string<char>>::_Rb_tree_impl" = type opaque
4+
5+
36
define internal i32 @"\01-[Shape square]"(%0*, i8*) {
47
%3 = alloca %0*, align 8
58
%4 = alloca i8*, align 8
69
store %0* %0, %0** %3, align 8
710
store i8* %1, i8** %4, align 8
811
ret i32 42
12+
}
13+
14+
define void @useStruct(%"struct.std::_Rb_tree<std::__cxx11::basic_string<char>>::_Rb_tree_impl"*) {
15+
ret void
916
}

tests/integration-tests/regression/test.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ def dump(tr) {
1919
dump(g.V().has('function', 'name', '-[Shape square]').valueMap('name'))
2020
// CHECK: name=[-[Shape square]]
2121

22+
dump(g.V().has('type', 'type_id', 'struct_type').valueMap('name'))
23+
// CHECK: name=[struct.std::_Rb_tree<std::__cxx11::basic_string<char>>::_Rb_tree_impl]
24+
2225
:exit
2326
// CHECK-EMPTY:

0 commit comments

Comments
 (0)