fix qr-code display (#3295)

* tagger.put_raw() has changes sematics and escapes strings on its own now

an explicit escaping leads to double escaping and to wrong display.

this should also improve lenght calculation,
as a quote and other specials counts as 1 character and not as 4-6.

* test encoding of generated qr-code-svg

* streamline function argument wording

use qrcode_description instead of raw_qrcode_description -
there is nothing "raw" in the argument,
it is a string as used throughout the app.
This commit is contained in:
bjoern
2022-05-05 11:55:05 +02:00
committed by GitHub
parent 9a0a3c4b00
commit 785667ec07
2 changed files with 24 additions and 2 deletions

View File

@@ -65,13 +65,12 @@ async fn generate_verification_qr(context: &Context) -> Result<String> {
}
fn inner_generate_secure_join_qr_code(
raw_qrcode_description: &str,
qrcode_description: &str,
qrcode_content: &str,
color: &str,
avatar: Option<Vec<u8>>,
avatar_letter: char,
) -> Result<String> {
let qrcode_description = &escaper::encode_minimal(raw_qrcode_description);
// config
let width = 515.0;
let height = 630.0;
@@ -262,3 +261,21 @@ fn inner_generate_secure_join_qr_code(
Ok(svg)
}
#[cfg(test)]
mod tests {
use super::*;
#[async_std::test]
async fn test_svg_escaping() {
let svg = inner_generate_secure_join_qr_code(
"descr123 \" < > &",
"qr-code-content",
"#000000",
None,
'X',
)
.unwrap();
assert!(svg.contains("descr123 &quot; &lt; &gt; &amp;"))
}
}