mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-08 16:54:00 +00:00
Add IndexError check to $firstwords function
This commit is contained in:
committed by
Philipp Wolfer
parent
dd5be66728
commit
becd3e0d7a
@@ -863,9 +863,12 @@ def func_firstwords(parser, text, length):
|
||||
if len(text) <= length:
|
||||
return text
|
||||
else:
|
||||
if text[length] == ' ':
|
||||
return text[:length]
|
||||
return text[:length].rsplit(' ', 1)[0]
|
||||
try:
|
||||
if text[length] == ' ':
|
||||
return text[:length]
|
||||
return text[:length].rsplit(' ', 1)[0]
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
||||
@script_function()
|
||||
|
||||
@@ -456,6 +456,8 @@ class ScriptParserTest(PicardTestCase):
|
||||
self.assertScriptResultEquals("$firstwords(Abc Def Ghi,0)", "")
|
||||
self.assertScriptResultEquals("$firstwords(Abc Def Ghi,NaN)", "")
|
||||
self.assertScriptResultEquals("$firstwords(Abc Def Ghi,)", "")
|
||||
self.assertScriptResultEquals("$firstwords(Abc Def Ghi,-2)", "Abc Def")
|
||||
self.assertScriptResultEquals("$firstwords(Abc Def Ghi,-50)", "")
|
||||
|
||||
def test_cmd_startswith(self):
|
||||
self.assertScriptResultEquals("$startswith(abc,a)", "1")
|
||||
|
||||
Reference in New Issue
Block a user