From 8813677ecb171e5d27cd582989c1d87b308c6df3 Mon Sep 17 00:00:00 2001 From: Jan Kahmen <36455663+kah-ja@users.noreply.github.com> Date: Mon, 17 Aug 2026 23:03:41 +0200 Subject: [PATCH] fix(core): keep the @import cleanup working in stringWithoutHTMLInjection the trailing while loop reuses the regex variable, which by then points at the angular brace pattern whenever stripAngular is YES. that pattern has two capture groups while the loop substitutes $1@im****$3, so NSRegularExpression raises NSInvalidArgumentException and the NS_HANDLER swallows it. give the @import pattern its own variable and use it in both the replacement and the loop. the replacement also used the template of the block above, which dropped the whole style element instead of masking the @import in place, so test_stringWithoutHTMLInjection failed. it passes again, and a case with stripAngular YES covers the loop. --- SoObjects/SOGo/NSString+Utilities.m | 11 ++++++----- Tests/Unit/TestNSString+Utilities.m | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 441d471eb..9e5898a15 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -942,12 +942,13 @@ static int cssEscapingCount; NSScanner *theScanner; NSError *error; NSUInteger numberOfMatches; - NSRegularExpression *regex; + NSRegularExpression *regex, *importRegex; text = nil; error = nil; result = [NSString stringWithString: self]; regex = nil; + importRegex = nil; NS_DURING { @@ -1056,9 +1057,9 @@ static int cssEscapingCount; result = [NSString stringWithString: newResult]; // Remove @import css (in style tags) - regex = [NSRegularExpression regularExpressionWithPattern:@"(<[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e.*)([\\s\\u200B \\\\0]*@[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*m[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*o[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*t)(.*<[\\s\\u200B \\\\0]*\\/[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e[\\s\\u200B \\\\0]*>)" + importRegex = [NSRegularExpression regularExpressionWithPattern:@"(<[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e.*)([\\s\\u200B \\\\0]*@[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*m[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*o[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*t)(.*<[\\s\\u200B \\\\0]*\\/[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e[\\s\\u200B \\\\0]*>)" options: NSRegularExpressionCaseInsensitive error:&error]; - newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onrep***="]; + newResult = [importRegex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"$1@im****$3"]; result = [NSString stringWithString: newResult]; @@ -1075,8 +1076,8 @@ static int cssEscapingCount; } newResult = result; - while([regex numberOfMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length])] > 0) { - newResult = [regex stringByReplacingMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length]) withTemplate:@"$1@im****$3"]; + while([importRegex numberOfMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length])] > 0) { + newResult = [importRegex stringByReplacingMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length]) withTemplate:@"$1@im****$3"]; } result = [NSString stringWithString: newResult]; } diff --git a/Tests/Unit/TestNSString+Utilities.m b/Tests/Unit/TestNSString+Utilities.m index 94efa8db9..fdddf10f1 100644 --- a/Tests/Unit/TestNSString+Utilities.m +++ b/Tests/Unit/TestNSString+Utilities.m @@ -110,6 +110,8 @@ testEquals([[NSString stringWithString:@"foobar
ABC
"] stringWithoutHTMLInjection: NO stripAngular: NO], @"
ABC
"); + // the @import cleanup must still run when angular interpolation is stripped as well + testEquals([[NSString stringWithString:@""] stringWithoutHTMLInjection: NO stripAngular: YES], @""); } - (void) test_stringCleanInvalidHTMLTags