File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -270,6 +270,7 @@ fn starts_with_ignore_case(string: &str, pattern: &str) -> bool {
270270/// The function should be called after a QR code is scanned.
271271/// The function takes the raw text scanned and checks what can be done with it.
272272pub async fn check_qr ( context : & Context , qr : & str ) -> Result < Qr > {
273+ let qr = qr. trim ( ) ;
273274 let qrcode = if starts_with_ignore_case ( qr, OPENPGP4FPR_SCHEME ) {
274275 decode_openpgp ( context, qr)
275276 . await
@@ -994,6 +995,17 @@ mod tests {
994995 }
995996 ) ;
996997
998+ // Test that QR code whitespace is stripped.
999+ // Users can copy-paste QR code contents and "scan"
1000+ // from the clipboard.
1001+ let qr = check_qr ( & ctx. ctx , " \t http://www.hello.com/hello \n \t \r \n " ) . await ?;
1002+ assert_eq ! (
1003+ qr,
1004+ Qr :: Url {
1005+ url: "http://www.hello.com/hello" . to_string( ) ,
1006+ }
1007+ ) ;
1008+
9971009 Ok ( ( ) )
9981010 }
9991011
@@ -1743,7 +1755,9 @@ mod tests {
17431755 ) ;
17441756
17451757 // Test URL without port.
1746- let res = set_config_from_qr ( & t, "https://t.me/socks?server=1.2.3.4" ) . await ;
1758+ //
1759+ // Also check that whitespace is trimmed.
1760+ let res = set_config_from_qr ( & t, " https://t.me/socks?server=1.2.3.4\n " ) . await ;
17471761 assert ! ( res. is_ok( ) ) ;
17481762 assert_eq ! ( t. get_config_bool( Config :: ProxyEnabled ) . await ?, true ) ;
17491763 assert_eq ! (
You can’t perform that action at this time.
0 commit comments