@@ -36,8 +36,9 @@ def parse(login_path: str, path=None) -> dict:
3636 )
3737 parser .read_string (read (path ), source = path )
3838 data = dict (parser .items (login_path ))
39- if 'port' in data :
40- data ['port' ] = int (data ['port' ])
39+ data = {key : _strip_quotes (value ) for key , value in data .items ()}
40+ if "port" in data :
41+ data ["port" ] = int (data ["port" ])
4142 return data
4243
4344
@@ -92,7 +93,7 @@ def _read_encrypted_file(f) -> bytes:
9293 length_buffer = f .read (_CIPHER_STORE_LENGTH )
9394 if len (length_buffer ) < _CIPHER_STORE_LENGTH :
9495 break
95- line_length , = struct .unpack ("<i" , length_buffer )
96+ ( line_length ,) = struct .unpack ("<i" , length_buffer )
9697 line = _read_line (f , line_length , decryptor )
9798 plaintext += line
9899
@@ -121,6 +122,17 @@ def _remove_pad(line):
121122 return line [:- pad_length ]
122123
123124
125+ def _strip_quotes (value ):
126+ """If a value is quoted, remove the quotes at the beginning and end, then
127+ un-escape any quote characters inside the string."""
128+ if value .startswith ('"' ) and value .endswith ('"' ):
129+ # This is a quoted string. Remove the first and
130+ # last quote, then unescape interior quotes.
131+ value = value [1 :- 1 ]
132+ value = value .replace ('\\ "' , '"' )
133+ return value
134+
135+
124136if __name__ == "__main__" :
125137 print (read ())
126138 print (parse ("test" ))
0 commit comments