Skip to content

Commit e922e71

Browse files
committed
🐛 fix: fix some corner cases in protobuf data
1 parent 847c347 commit e922e71

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/biliass/src/biliass/biliass.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def get_position(InputPos, isHeight):
140140
return get_position(InputPos, isHeight)
141141

142142
try:
143-
comment_args = safe_list(json.loads(c[3]))
143+
special_comment_data = json.loads(c[3])
144+
if not isinstance(special_comment_data, list):
145+
raise ValueError("Invalid comment")
146+
comment_args = safe_list(special_comment_data)
144147
text = ass_escape(str(comment_args[4]).replace("/n", "\n"))
145148
from_x = comment_args.get(0, 0)
146149
from_y = comment_args.get(1, 0)
@@ -588,8 +591,11 @@ def convert_type2(row, height, bottom_reserved):
588591

589592
class safe_list(list):
590593
def get(self, index, default=None):
594+
def is_empty(value):
595+
return value is None or value == ""
596+
591597
try:
592-
return self[index]
598+
return self[index] if not is_empty(self[index]) else default
593599
except IndexError:
594600
return default
595601

0 commit comments

Comments
 (0)