Skip to content

Commit

Permalink
#6467: Escape quotes and line breaks when writing entity key values.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 27, 2024
1 parent 2319e6e commit 8345fb0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions radiantcore/map/format/Doom3MapWriter.cpp
Expand Up @@ -14,10 +14,12 @@ namespace map
namespace
{

// Escape the line break characters in the given input string to \n
inline std::string escapeLineBreaks(const std::string& input)
// Escape line breaks and quotes in the given input string
inline std::string escapeEntityKeyValue(const std::string& input)
{
return string::replace_all_copy(input, "\n", "\\n");
auto result = string::replace_all_copy(input, "\n", "\\n");
string::replace_all(result, "\"", "\\\""); // replace " with \"
return result;
}

}
Expand Down Expand Up @@ -55,7 +57,7 @@ void Doom3MapWriter::writeEntityKeyValues(const IEntityNodePtr& entity, std::ost
// Export the entity key values
entity->getEntity().forEachKeyValue([&](const std::string& key, const std::string& value)
{
stream << "\"" << key << "\" \"" << escapeLineBreaks(value) << "\"" << std::endl;
stream << "\"" << escapeEntityKeyValue(key) << "\" \"" << escapeEntityKeyValue(value) << "\"" << std::endl;
});
}

Expand Down

0 comments on commit 8345fb0

Please sign in to comment.