Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an unescaped apostrophe in a literal defined in strings.xml cause my app to crash?

Tags:

android

Google's official documentation mentions:

Escaping apostrophes and quotes

If you have an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other type of enclosing quotes. For example, here are some stings that do and don't work:

<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>
<string name="bad_example">This doesn't work</string>
<string name="bad_example_2">XML encodings don&apos;t work</string>

My question is: Would unescaped quotes cause the application to crash or would it just have no effect and the quotes won't appear in the app UI? Would it crash on specific Android versions? I ask this because if I don't escape this symbol, Eclipse SDK gives me compilation errors but I came across a third-party app code which does not escape these characters, it crashes randomly and I'd like to confirm that this is/ is not one of the possible reasons for the crash.

like image 272
Gaurav Avatar asked Jan 24 '11 13:01

Gaurav


1 Answers

The "third-party app code" might not be up-to-date. The requirement to escape quotes has been introduced at some point in time last year (don't remember exactly when) by an updated aapt.

The backslash is just a hint for aapt, it is not making its way into the apk file. Thus, I would not expect an app to crash for this specific reason.

like image 159
Michael Avatar answered Oct 13 '22 20:10

Michael