Skip to content

fix: roundtrip XML values containing CDATA-like strings#3826

Merged
iBotPeaches merged 2 commits intoiBotPeaches:masterfrom
vbfox:xml-resources-cdata-escape
Mar 25, 2025
Merged

fix: roundtrip XML values containing CDATA-like strings#3826
iBotPeaches merged 2 commits intoiBotPeaches:masterfrom
vbfox:xml-resources-cdata-escape

Conversation

@vbfox
Copy link
Contributor

@vbfox vbfox commented Mar 21, 2025

This fixes the case where the value (text content) for an XML element that needs to be escaped contains text looking like the ending of a CDATA tag (]]>) as this must be escaped.

Relevant specification: https://www.w3.org/TR/xml/#syntax

In the content of elements, character data is any string of characters which does not contain the start-delimiter of any markup and does not include the CDATA-section-close delimiter, " ]]> ".

This fixes the case where the value for an XML element that needs to be
escaped contains text looking like the ending of a CDATA tag (']]>') as this
must be escaped.
@iBotPeaches
Copy link
Owner

Do you have a sample string from something in the wild that led to this? I understand these samples and description, but trying to piece together with something in the wild to understand the flaw Apktool originally had in escaping.

@vbfox
Copy link
Contributor Author

vbfox commented Mar 25, 2025

@iBotPeaches You can find an example in the french resources of the uber app:

apkeep -a com.ubercab -d google-play -o split_apk=true,locale=fr_FR .
cd com.ubercab
java -jar ~/apktool_2.11.1.jar d com.ubercab.config.fr.apk
cat com.ubercab.config.fr/res/values-fr/strings.xml

This will look something like this:

<?xml version="1.0" encoding="utf-8"?>
<resources> 
    <string name="account_switcher_account_limit_error_modal_message">"&lt;![CDATA[Vous avez atteint la limite de votre compte. Appuyez sur l'icône &lt;b>Gérer&lt;/b> (icône en forme d'engrenage) pour vous déco
  nnecter de l'un de vos comptes avant d'en ajouter un autre.]]>"</string>
</resources>

Copy link
Owner

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just a few minor nitpicks.

* Reorder methods in ResXmlEncoderTest
* Fix indent of 'throws' line in XmlUtils
@vbfox vbfox force-pushed the xml-resources-cdata-escape branch from 371f1c1 to 8f564d2 Compare March 25, 2025 13:49
@vbfox
Copy link
Contributor Author

vbfox commented Mar 25, 2025

Nitpicks should be fixed now

@vbfox vbfox requested a review from iBotPeaches March 25, 2025 13:50
@iBotPeaches iBotPeaches merged commit ec25e65 into iBotPeaches:master Mar 25, 2025
25 checks passed
@iBotPeaches iBotPeaches added this to the 2.11.2 milestone Mar 25, 2025
iBotPeaches added a commit to iBotPeaches/apktool.org that referenced this pull request Mar 25, 2025
@iBotPeaches
Copy link
Owner

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants