diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/translations-converter/Cargo.toml | 1 | ||||
| -rw-r--r-- | android/translations-converter/src/android.rs | 19 |
2 files changed, 5 insertions, 15 deletions
diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml index fadfdc6396..a5f01aa386 100644 --- a/android/translations-converter/Cargo.toml +++ b/android/translations-converter/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +htmlize = "0.5" lazy_static = "1" regex = "1" serde = { version = "1", features = ["derive"] } diff --git a/android/translations-converter/src/android.rs b/android/translations-converter/src/android.rs index 8360b34f1d..9cd634b1b7 100644 --- a/android/translations-converter/src/android.rs +++ b/android/translations-converter/src/android.rs @@ -10,9 +10,6 @@ lazy_static! { static ref LINE_BREAKS: Regex = Regex::new(r"\s*\n\s*").unwrap(); static ref APOSTROPHES: Regex = Regex::new(r"\\'").unwrap(); static ref PARAMETERS: Regex = Regex::new(r"%[0-9]*\$").unwrap(); - static ref AMPERSANDS: Regex = Regex::new(r"&").unwrap(); - static ref LESS_THANS: Regex = Regex::new(r"<").unwrap(); - static ref GREATER_THANS: Regex = Regex::new(r">").unwrap(); } /// Contents of an Android string resources file. @@ -293,13 +290,10 @@ pub struct StringValue(String); impl From<&str> for StringValue { fn from(string: &str) -> Self { - let value_with_parameters = string + let value_with_parameters = htmlize::unescape(string) .replace(r"\", r"\\") .replace("\"", "\\\"") - .replace(r"'", r"\'") - .replace("&", "&") - .replace("<", "<") - .replace(">", ">"); + .replace(r"'", r"\'"); let mut parts = value_with_parameters.split("%"); let mut value = parts.next().unwrap().to_owned(); @@ -324,14 +318,9 @@ impl StringValue { let value = APOSTROPHES.replace_all(&value, "'"); // Mark where parameters are positioned, removing the parameter index let value = PARAMETERS.replace_all(&value, "%"); - // Unescape ampersands - let value = AMPERSANDS.replace_all(&value, "&"); - // Unescape less thans - let value = LESS_THANS.replace_all(&value, "<"); - // Unescape greater thans - let value = GREATER_THANS.replace_all(&value, ">"); - self.0 = value.into_owned(); + // Unescape XML characters + self.0 = htmlize::escape_text(value.as_bytes()); } /// Clones the internal string value. |
