Skip to content

Commit

Permalink
Fix escaping of embedded quotes. (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
manodasanW authored Apr 30, 2022
1 parent 1182367 commit f893b8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ And this is another one"
void f();
}

[attr_string("a string with embedded quotes, like the string \"quotes\"")]
[attr_string("a string with embedded escape characters, like the string \"quotes\" and string \\\"quotes\\\" and string \'char\'")]
runtimeclass EmbeddedQuotesTest
{
void f();
Expand Down
14 changes: 14 additions & 0 deletions src/cswinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1502,10 +1502,24 @@ remove => %;
},
[&](std::string_view type_name)
{
bool previous_char_escape = false;
std::string sanitized_type_name;
sanitized_type_name.reserve(type_name.length() * 2);
for (const auto& c : type_name)
{
if (c == '\\' && !previous_char_escape)
{
previous_char_escape = true;
continue;
}

// We only handle the following escape characters for now.
if (previous_char_escape && c != '\\' && c != '\'' && c != '"')
{
sanitized_type_name += '\\';
}
previous_char_escape = false;

sanitized_type_name += c;
if (c == '"')
{
Expand Down

0 comments on commit f893b8d

Please sign in to comment.