Skip to content

Commit

Permalink
4.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
molicechen committed Dec 23, 2021
1 parent 75aa32b commit 137e54f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion QMUIKit/QMUIComponents/QMUIButton/QMUIButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ @implementation QMUIButton

- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self didInitialize];
self.tintColor = ButtonTintColor;
[self setTitleColor:self.tintColor forState:UIControlStateNormal];// 初始化时 adjustsTitleTintColorAutomatically 还是 NO,所以这里手动把 titleColor 设置为 tintColor 的值

// iOS7以后的button,sizeToFit后默认会自带一个上下的contentInsets,为了保证按钮大小即为内容大小,这里直接去掉,改为一个最小的值。
self.contentEdgeInsets = UIEdgeInsetsMake(CGFLOAT_MIN, 0, CGFLOAT_MIN, 0);

// 放在后面,让前面的默认值可以被子类重写的 didInitialize 覆盖
[self didInitialize];
}
return self;
}
Expand Down
22 changes: 11 additions & 11 deletions QMUIKit/UIKitExtensions/QMUIStringPrivate.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@ + (void)qmuisafety_NSString {

// index 越界
{
BOOL isValidddatedIndex = index <= selfObject.length;
if (!isValidddatedIndex) {
BOOL isValidatedIndex = index <= selfObject.length;
if (!isValidatedIndex) {
NSString *logString = [NSString stringWithFormat:@"%@ 传入了一个超过字符串长度的 index: %@,原字符串为: %@(%@)", NSStringFromSelector(originCMD), @(index), selfObject, @(selfObject.length)];
NSAssert(NO, logString);
QMUILogWarn(@"QMUIStringSafety", @"%@", logString);
return nil;// 系统 substringFromIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
return @"";// 系统 substringFromIndex: 返回值的标志是 nonnull
}
}

// 保护从 emoji 等 ComposedCharacterSequence 中间裁剪的场景
{
if (index < selfObject.length) {
NSRange range = [selfObject rangeOfComposedCharacterSequenceAtIndex:index];
BOOL isValidddatedIndex = range.location == index || NSMaxRange(range) == index;
if (!isValidddatedIndex) {
BOOL isValidatedIndex = range.location == index || NSMaxRange(range) == index;
if (!isValidatedIndex) {
NSString *logString = [NSString stringWithFormat:@"试图在 ComposedCharacterSequence 中间用 %@ 裁剪字符串,可能导致乱码、crash。原字符串为“%@”(%@),index 为 %@,命中的 ComposedCharacterSequence range 为 %@", NSStringFromSelector(originCMD), selfObject, @(selfObject.length), @(index), NSStringFromRange(range)];
NSAssert(NO, logString);
QMUILogWarn(@"QMUIStringSafety", @"%@", logString);
Expand All @@ -197,21 +197,21 @@ + (void)qmuisafety_NSString {

// index 越界
{
BOOL isValidddatedIndex = index <= selfObject.length;
if (!isValidddatedIndex) {
BOOL isValidatedIndex = index <= selfObject.length;
if (!isValidatedIndex) {
NSString *logString = [NSString stringWithFormat:@"%@ 传入了一个超过字符串长度的 index: %@,原字符串为: %@(%@)", NSStringFromSelector(originCMD), @(index), selfObject, @(selfObject.length)];
NSAssert(NO, logString);
QMUILogWarn(@"QMUIStringSafety", @"%@", logString);
return nil;// 系统 substringToIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
return @"";// 系统 substringToIndex: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
}
}

// 保护从 emoji 等 ComposedCharacterSequence 中间裁剪的场景
{
if (index < selfObject.length) {
NSRange range = [selfObject rangeOfComposedCharacterSequenceAtIndex:index];
BOOL isValidddatedIndex = range.location == index;
if (!isValidddatedIndex) {
BOOL isValidatedIndex = range.location == index;
if (!isValidatedIndex) {
NSString *logString = [NSString stringWithFormat:@"试图在 ComposedCharacterSequence 中间用 %@ 裁剪字符串,可能导致乱码、crash。原字符串为“%@”(%@),index 为 %@,命中的 ComposedCharacterSequence range 为 %@", NSStringFromSelector(originCMD), selfObject, @(selfObject.length), @(index), NSStringFromRange(range)];
NSAssert(NO, logString);
QMUILogWarn(@"QMUIStringSafety", @"%@", logString);
Expand Down Expand Up @@ -240,7 +240,7 @@ + (void)qmuisafety_NSString {
NSString *logString = [NSString stringWithFormat:@"%@ 传入了一个超过字符串长度的 range: %@,原字符串为: %@(%@)", NSStringFromSelector(originCMD), NSStringFromRange(range), selfObject, @(selfObject.length)];
NSAssert(NO, logString);
QMUILogWarn(@"QMUIStringSafety", @"%@", logString);
return nil;// 系统 substringWithRange: 返回值的标志是 nonnull,但返回 nil 比返回 @"" 更安全
return @"";// 系统 substringWithRange: 返回值的标志是 nonnull
}
}

Expand Down

0 comments on commit 137e54f

Please sign in to comment.