JJException icon indicating copy to clipboard operation
JJException copied to clipboard

NSMutableAttributedString的hook有必要hook initWithString这个方法吗,系统的方法传个空参数也不会崩溃

Open renyufei8023 opened this issue 3 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Please complete the following information

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Version [e.g. 22]

renyufei8023 avatar Sep 15 '20 07:09 renyufei8023

[[NSMutableAttributedString alloc] initWithString:nil]

这种空参数会闪退的

jezzmemo avatar Sep 19 '20 15:09 jezzmemo

看了一下系统的如果传空的确会崩溃的,是其他第三方hook了这个方法处理了空参数。 下面是崩溃的代码,for循环那里崩溃了

NSString *regulaStr = @"((http|ftp|https)://)(([a-zA-Z0-9\\._-]+\\.[a-zA-Z]{2,6})|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))(:[0-9]{1,4})*(/[a-zA-Z0-9\\&%_\\./-~-]*)?";
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr
                                                                           options:NSRegularExpressionCaseInsensitive
                                                                             error:nil];
    NSArray *arrayOfAllMatches = [regex matchesInString:att.string options:0 range:NSMakeRange(0, [att length])];
    for (NSTextCheckingResult *match in arrayOfAllMatches) {
        [att yy_setTextHighlightRange:match.range color:UIColorMakeWithRGBA(33, 99, 170, 1.0) backgroundColor:nil tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[text.string substringWithRange:range]] options:@{} completionHandler:nil];
        }];
    }

renyufei8023 avatar Sep 21 '20 01:09 renyufei8023