forked from LBRYCommunity/lbry-sdk
fix error when resolving true/false/floats and also prevent other keys from being parsed as boolean, int, or float in CLI
This commit is contained in:
parent
0c2d049c90
commit
b2f0dedefb
2 changed files with 15 additions and 3 deletions
|
@ -133,6 +133,8 @@ def main():
|
|||
def guess_type(x, key=None):
|
||||
if not isinstance(x, (unicode, str)):
|
||||
return x
|
||||
if key in ('uri', 'channel_name', 'name', 'file_name', 'download_directory'):
|
||||
return x
|
||||
if x in ('true', 'True', 'TRUE'):
|
||||
return True
|
||||
if x in ('false', 'False', 'FALSE'):
|
||||
|
@ -143,8 +145,6 @@ def guess_type(x, key=None):
|
|||
except ValueError:
|
||||
# not a float
|
||||
pass
|
||||
if key == "uri":
|
||||
return x
|
||||
try:
|
||||
return int(x)
|
||||
except ValueError:
|
||||
|
|
|
@ -7,7 +7,6 @@ class DaemonCLITests(unittest.TestCase):
|
|||
self.assertEqual('0.3.8', DaemonCLI.guess_type('0.3.8'))
|
||||
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||
self.assertEqual(3, DaemonCLI.guess_type('3'))
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="uri"))
|
||||
self.assertEqual('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA==', DaemonCLI.guess_type('VdNmakxFORPSyfCprAD/eDDPk5TY9QYtSA=='))
|
||||
self.assertEqual(0.3, DaemonCLI.guess_type('0.3'))
|
||||
self.assertEqual(True, DaemonCLI.guess_type('TRUE'))
|
||||
|
@ -16,3 +15,16 @@ class DaemonCLITests(unittest.TestCase):
|
|||
self.assertEqual(False, DaemonCLI.guess_type('FALSE'))
|
||||
self.assertEqual(False, DaemonCLI.guess_type('false'))
|
||||
self.assertEqual(False, DaemonCLI.guess_type('False'))
|
||||
|
||||
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="uri"))
|
||||
self.assertEqual('0.3', DaemonCLI.guess_type('0.3', key="uri"))
|
||||
self.assertEqual('True', DaemonCLI.guess_type('True', key="uri"))
|
||||
self.assertEqual('False', DaemonCLI.guess_type('False', key="uri"))
|
||||
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="file_name"))
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="name"))
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="download_directory"))
|
||||
self.assertEqual('3', DaemonCLI.guess_type('3', key="channel_name"))
|
||||
|
||||
self.assertEqual(3, DaemonCLI.guess_type('3', key="some_other_thing"))
|
||||
|
|
Loading…
Add table
Reference in a new issue