Skip to content

Commit

Permalink
fix: phonetic may be NSNull, [NSNull length] cause crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tisfeng committed Dec 16, 2023
1 parent 6d77833 commit d426166
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,17 @@ - (void)refreshWithResult:(EZQueryResult *)result {

// 部分没有音标文本
EZLabel *phoneticLabel = nil;
if (obj.value.length) {

// Fix: SIGABRT: -[NSNull length]: unrecognized selector sent to instance 0x7ff85c514b40
NSString *phonetic = obj.value;
if ([phonetic isKindOfClass:NSString.class] && phonetic.length) {
phoneticLabel = [[EZLabel alloc] init];
[self addSubview:phoneticLabel];
phoneticLabel.textContainer.lineFragmentPadding = 0;
phoneticLabel.font = [NSFont systemFontOfSize:textFont.pointSize];

// ???: WTF, why Baidu phonetic contain '\n', e.g. ceil "siːl\n"
NSString *phonetic = [obj.value trim];
phoneticLabel.text = [NSString stringWithFormat:@"/ %@ /", phonetic];
phoneticLabel.text = [NSString stringWithFormat:@"/ %@ /", phonetic.trim];
[phoneticLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(phoneticTagLabel.mas_right).offset(kHorizontalMargin_8);
make.centerY.equalTo(phoneticTagLabel);
Expand Down

0 comments on commit d426166

Please sign in to comment.