@@ -176,7 +176,7 @@ def test_echochar_replaces_input_with_asterisks(self):
176176 mock_input .assert_called_once_with ('Password: ' , textio (), textio (), '*' )
177177 self .assertEqual (result , mock_result )
178178
179- def test_input_with_echochar (self ):
179+ def test_input_with_control_characters (self ):
180180 passwd = 'my1pa$$word!'
181181 mock_input = StringIO (f'{ passwd } \n ' )
182182 mock_output = StringIO ()
@@ -187,6 +187,18 @@ def test_input_with_echochar(self):
187187 self .assertEqual (result , passwd )
188188 self .assertEqual ('Password: ************' , mock_output .getvalue ())
189189
190+ def test_control_chars_with_echochar (self ):
191+ passwd = 'pass\t wd\b '
192+ expect_result = 'pass\t w'
193+ mock_input = StringIO (f'{ passwd } \n ' )
194+ mock_output = StringIO ()
195+ with mock .patch ('sys.stdin' , mock_input ), \
196+ mock .patch ('sys.stdout' , mock_output ):
197+ result = getpass ._input_with_echochar ('Password: ' , mock_output ,
198+ mock_input , '*' )
199+ self .assertEqual (result , expect_result )
200+ self .assertEqual ('Password: *******\x08 \x08 ' , mock_output .getvalue ())
201+
190202
191203if __name__ == "__main__" :
192204 unittest .main ()
0 commit comments