summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-13 13:32:45 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-08-11 22:59:38 +0000
commit03b7ab4bacb627198ee45ec9dbce627c29f871a5 (patch)
treef578bd42b8decae2031cc3a27a4b815ebe00d0d8 /android
parent3b12e1ffa809f52d023789eff57a9ad61467f7f8 (diff)
downloadmullvadvpn-03b7ab4bacb627198ee45ec9dbce627c29f871a5.tar.xz
mullvadvpn-03b7ab4bacb627198ee45ec9dbce627c29f871a5.zip
Handle escaped apostrophes in Android strings
Diffstat (limited to 'android')
-rw-r--r--android/translations-converter/src/android.rs14
-rw-r--r--android/translations-converter/src/main.rs13
2 files changed, 22 insertions, 5 deletions
diff --git a/android/translations-converter/src/android.rs b/android/translations-converter/src/android.rs
index 8a4a89f91e..9a7fd1c99a 100644
--- a/android/translations-converter/src/android.rs
+++ b/android/translations-converter/src/android.rs
@@ -56,6 +56,20 @@ impl IntoIterator for StringResources {
}
}
+impl StringResource {
+ /// Create a new Android string resource entry.
+ ///
+ /// The name is the resource ID, and the value will be properly escaped.
+ pub fn new(name: String, value: &str) -> Self {
+ let value = value
+ .replace(r"\", r"\\")
+ .replace("\"", "\\\"")
+ .replace(r"'", r"\'");
+
+ StringResource { name, value }
+ }
+}
+
// Unfortunately, direct serialization to XML isn't working correctly.
impl Display for StringResources {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
diff --git a/android/translations-converter/src/main.rs b/android/translations-converter/src/main.rs
index 80dcf04595..09296f87fe 100644
--- a/android/translations-converter/src/main.rs
+++ b/android/translations-converter/src/main.rs
@@ -28,12 +28,15 @@ fn main() {
serde_xml_rs::from_reader(strings_file).expect("Failed to read string resources file");
let line_breaks = Regex::new(r"\s*\n\s*").unwrap();
+ let apostrophes = Regex::new(r"\\'").unwrap();
let known_strings: HashMap<_, _> = string_resources
.into_iter()
.map(|string| {
let android_id = string.name;
- let string_value = line_breaks.replace_all(&string.value, " ").into_owned();
+ let without_line_breaks = line_breaks.replace_all(&string.value, " ");
+ let without_escaped_apostrophes = apostrophes.replace_all(&without_line_breaks, "'");
+ let string_value = without_escaped_apostrophes.into_owned();
(string_value, android_id)
})
@@ -100,10 +103,10 @@ fn generate_translations(
for translation in translations {
if let Some(android_key) = known_strings.remove(&translation.id) {
- localized_resource.push(android::StringResource {
- name: android_key,
- value: translation.value,
- });
+ localized_resource.push(android::StringResource::new(
+ android_key,
+ &translation.value,
+ ));
}
}