diff options
author | Tor Norbye <tnorbye@google.com> | 2012-09-18 18:08:37 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-09-18 18:08:52 -0700 |
commit | 454f0e05d3e202320b0cd7bc176360458e88658e (patch) | |
tree | 0763e42a33ff136e89ed56a44fd38f51ec6a698b /templates/activities/MasterDetailFlow/root/res | |
parent | 005c9879219df96beee1d1e28b82b3b0e19bc2ed (diff) | |
download | sdk-454f0e05d3e202320b0cd7bc176360458e88658e.zip sdk-454f0e05d3e202320b0cd7bc176360458e88658e.tar.gz sdk-454f0e05d3e202320b0cd7bc176360458e88658e.tar.bz2 |
37497: Templates should escape string literals in resource files
If the user enters an activity title like "Android's Tools" in the new
template wizard, an invalid strings.xml file is generated, since the
apostrophe is not properly escaped.
To fix this, there's a new string conversion method in the template
engine, "escapeXmlString", which will perform all the necessary
conversions.
It also adds two other XML escaping functions: one to escape text to
be suitable for XML attribute values, and one to be suitable for XML
text values.
Finally, when verifying this, I discovered that if I inserted
ampersands in the MasterDetail template, I ended up with errors in
various places there a filename was derived from the input string. To
help make this work better, there's also a new "extractLetters" method
which pulls all the characters out of a string (effectively stripping
whitespace and punctuation).
In addition to the above 4 new string conversion methods, the
templates have been updated to use them, and the template format
documentation updated.
Change-Id: I4d4e854ab78d63bc86b8eb0fb9d92246534615e7
Diffstat (limited to 'templates/activities/MasterDetailFlow/root/res')
3 files changed, 4 insertions, 4 deletions
diff --git a/templates/activities/MasterDetailFlow/root/res/values-large/refs.xml.ftl b/templates/activities/MasterDetailFlow/root/res/values-large/refs.xml.ftl index 3008e2e..97215c3 100644 --- a/templates/activities/MasterDetailFlow/root/res/values-large/refs.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/values-large/refs.xml.ftl @@ -6,5 +6,5 @@ For more on layout aliases, see: http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters --> - <item type="layout" name="activity_${collection_name}">@layout/activity_${objectKind?lower_case}_twopane</item> + <item type="layout" name="activity_${collection_name}">@layout/activity_${extractLetters(objectKind?lower_case)}_twopane</item> </resources> diff --git a/templates/activities/MasterDetailFlow/root/res/values-sw600dp/refs.xml.ftl b/templates/activities/MasterDetailFlow/root/res/values-sw600dp/refs.xml.ftl index c698e6e..d592404 100644 --- a/templates/activities/MasterDetailFlow/root/res/values-sw600dp/refs.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/values-sw600dp/refs.xml.ftl @@ -7,5 +7,5 @@ For more on layout aliases, see: http://developer.android.com/training/multiscreen/screensizes.html#TaskUseAliasFilters --> - <item type="layout" name="activity_${collection_name}">@layout/activity_${objectKind?lower_case}_twopane</item> + <item type="layout" name="activity_${collection_name}">@layout/activity_${extractLetters(objectKind?lower_case)}_twopane</item> </resources> diff --git a/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl b/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl index 8c555ae..ea882bc 100644 --- a/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl +++ b/templates/activities/MasterDetailFlow/root/res/values/strings.xml.ftl @@ -1,6 +1,6 @@ <resources> <#if !isNewProject> - <string name="title_${collection_name}">${objectKindPlural}</string> + <string name="title_${collection_name}">${escapeXmlString(objectKindPlural)}</string> </#if> - <string name="title_${detail_name}">${objectKind} Detail</string> + <string name="title_${detail_name}">${escapeXmlString(objectKind)} Detail</string> </resources> |