File tree 1 file changed +15
-1
lines changed
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 {
270
270
/// The function should be called after a QR code is scanned.
271
271
/// The function takes the raw text scanned and checks what can be done with it.
272
272
pub async fn check_qr ( context : & Context , qr : & str ) -> Result < Qr > {
273
+ let qr = qr. trim ( ) ;
273
274
let qrcode = if starts_with_ignore_case ( qr, OPENPGP4FPR_SCHEME ) {
274
275
decode_openpgp ( context, qr)
275
276
. await
@@ -994,6 +995,17 @@ mod tests {
994
995
}
995
996
) ;
996
997
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
+
997
1009
Ok ( ( ) )
998
1010
}
999
1011
@@ -1743,7 +1755,9 @@ mod tests {
1743
1755
) ;
1744
1756
1745
1757
// 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 ;
1747
1761
assert ! ( res. is_ok( ) ) ;
1748
1762
assert_eq ! ( t. get_config_bool( Config :: ProxyEnabled ) . await ?, true ) ;
1749
1763
assert_eq ! (
You can’t perform that action at this time.
0 commit comments