Skip to content

Commit

Permalink
Fix writing out strings with embedded quote marks in custom attributes (
Browse files Browse the repository at this point in the history
#1038)

* Fix writing out strings with embedded quote marks in custom attributes

* indent

* indent
  • Loading branch information
asklar authored Nov 2, 2021
1 parent 8806f83 commit 3524776
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ And this is another one"
void f();
}

[attr_string("a string with embedded quotes, like the string \"quotes\"")]
runtimeclass EmbeddedQuotesTest
{
void f();
}

// Compile time test for sub windows namespace
namespace Windows
{
Expand Down
12 changes: 11 additions & 1 deletion src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,17 @@ remove => %;
},
[&](std::string_view type_name)
{
w.write("^@\"%\"", type_name);
std::string sanitized_type_name;
sanitized_type_name.reserve(type_name.length() * 2);
for (const auto& c : type_name)
{
sanitized_type_name += c;
if (c == '"')
{
sanitized_type_name += c;
}
}
w.write("^@\"%\"", sanitized_type_name);
},
[&](auto&&)
{
Expand Down

0 comments on commit 3524776

Please sign in to comment.