Fix project name not escaped in Cordova generated config.xml

This commit is contained in:
Florian Rival
2020-03-05 21:21:27 +00:00
parent 4362e8dd42
commit c5ad9715df
3 changed files with 25 additions and 2 deletions

View File

@@ -95,6 +95,14 @@ void Serializer::FromXML(SerializerElement& element,
}
#endif
gd::String Serializer::ToEscapedXMLString(const gd::String& str) {
return str.FindAndReplace("&", "&")
.FindAndReplace("'", "'")
.FindAndReplace("\"", """)
.FindAndReplace("<", "&lt;")
.FindAndReplace(">", "&gt;");
}
namespace {
/**

View File

@@ -27,14 +27,26 @@ class GD_CORE_API Serializer {
static void FromXML(SerializerElement& element,
const TiXmlElement* xmlElement);
#endif
/**
* \brief Escape a string for inclusion in a XML tag
*/
static gd::String ToEscapedXMLString(const gd::String& str);
///@}
/** \name JSON serialization.
* Serialize a SerializerElement from/to JSON.
*/
///@{
/**
* \brief Serialize a gd::SerializerElement to a JSON string.
*/
static gd::String ToJSON(const SerializerElement& element);
static SerializerElement FromJSON(const std::string& json);
/**
* \brief Parse a JSON string and returns a gd::SerializerElement for it.
*/
static SerializerElement FromJSON(const gd::String& json) {
return FromJSON(json.ToUTF8());
}

View File

@@ -267,8 +267,11 @@ bool ExporterHelper::ExportCordovaFiles(const gd::Project &project,
gd::String str =
fs.ReadFile(gdjsRoot + "/Runtime/Cordova/config.xml")
.FindAndReplace("GDJS_PROJECTNAME", project.GetName())
.FindAndReplace("GDJS_PACKAGENAME", project.GetPackageName())
.FindAndReplace("GDJS_PROJECTNAME",
gd::Serializer::ToEscapedXMLString(project.GetName()))
.FindAndReplace(
"GDJS_PACKAGENAME",
gd::Serializer::ToEscapedXMLString(project.GetPackageName()))
.FindAndReplace("GDJS_ORIENTATION", project.GetOrientation())
.FindAndReplace("GDJS_PROJECTVERSION", project.GetVersion())
.FindAndReplace("<!-- GDJS_ICONS_ANDROID -->", makeIconsAndroid())