🔒️ (locale): Escapa argumentos texto en using()
Los argumentos de `with_arg()` pueden venir de datos de usuario y `using()` los insertaba sin escapar. Ahora se escapan, y `with_markup()` añade argumentos con marcado HTML de confianza que se insertan tal cual.
This commit is contained in:
parent
3170f9a4d0
commit
0bcc7e5236
3 changed files with 109 additions and 40 deletions
|
|
@ -30,6 +30,42 @@ async fn translation_with_args() {
|
|||
assert_eq!(translation, Some("¡Hola, Manuel!".to_string()));
|
||||
}
|
||||
|
||||
// Text arguments may come from user data: `using()` must not let them inject markup.
|
||||
#[pagetop::test]
|
||||
async fn using_escapes_text_args() {
|
||||
setup().await;
|
||||
|
||||
let lc = Lc::l("test_hello_user").with_arg("userName", r#"<a href="x">Ana & "Luis"</a>"#);
|
||||
assert_eq!(
|
||||
lc.using(&Locale::resolve("es-ES")).into_string(),
|
||||
"¡Hola, <a href="x">Ana & "Luis"</a>!"
|
||||
);
|
||||
}
|
||||
|
||||
// `lookup()` returns plain text, escaped later where it is used (e.g. in an attribute).
|
||||
#[pagetop::test]
|
||||
async fn lookup_does_not_escape_text_args() {
|
||||
setup().await;
|
||||
|
||||
let lc = Lc::l("test_hello_user").with_arg("userName", "Ana & <Luis>");
|
||||
assert_eq!(
|
||||
lc.lookup(&Locale::resolve("es-ES")),
|
||||
Some("¡Hola, Ana & <Luis>!".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn using_keeps_markup_args() {
|
||||
setup().await;
|
||||
|
||||
let name = "Ana & Luis";
|
||||
let lc = Lc::l("test_hello_user").with_markup("userName", html! { strong { (name) } });
|
||||
assert_eq!(
|
||||
lc.using(&Locale::resolve("es-ES")).into_string(),
|
||||
"¡Hola, <strong>Ana & Luis</strong>!"
|
||||
);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn translation_with_plural_and_select() {
|
||||
setup().await;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue