File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ use clap::{arg, Command};
4
4
use num_bigint:: BigUint ;
5
5
use num_traits:: Num ;
6
6
7
+ use crate :: applet:: SliceExt ;
8
+
7
9
pub struct BaseIntApplet {
8
10
source_radix : Option < u32 > ,
9
11
target_radix : u32 ,
@@ -50,13 +52,16 @@ impl Applet for BaseIntApplet {
50
52
}
51
53
52
54
fn process ( & self , val : Vec < u8 > ) -> Result < Vec < u8 > > {
55
+ // Remove whitespace to make conversions work with stdin input
56
+ let val = val. trim ( ) ;
57
+
53
58
let ( srcrad, int) = if let Some ( src) = self . source_radix {
54
59
(
55
60
src,
56
61
BigUint :: parse_bytes ( & val, src) . context ( "Could not convert input" ) ?,
57
62
)
58
63
} else {
59
- let int_str = String :: from_utf8 ( val) . context ( "Could not convert value to string" ) ? ;
64
+ let int_str = String :: from_utf8_lossy ( val) ;
60
65
61
66
// Base was not specified, check standard prefixes
62
67
if int_str. len ( ) > 2 && & int_str[ 0 ..2 ] == "0x" {
@@ -122,6 +127,17 @@ mod tests {
122
127
. success ( ) ;
123
128
}
124
129
130
+ #[ test]
131
+ fn test_base_cli_stdin ( ) {
132
+ assert_cmd:: Command :: cargo_bin ( "rsbkb" )
133
+ . expect ( "Could not run binary" )
134
+ . args ( & [ "base" ] )
135
+ . write_stdin ( "0xA\n " )
136
+ . assert ( )
137
+ . stdout ( "10" )
138
+ . success ( ) ;
139
+ }
140
+
125
141
#[ test]
126
142
fn test_base_cli_arg_to ( ) {
127
143
assert_cmd:: Command :: cargo_bin ( "rsbkb" )
You can’t perform that action at this time.
0 commit comments