From 1059d81fc278c9a91faf809072dbcda7f91fda21 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Tue, 17 Nov 2026 09:04:04 -0800 Subject: [PATCH] fix(ios): end each bold or strikethrough run at its first closing marker (#9559) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bold and strikethrough runs in iOS push notification bodies now end at their first closing marker, so a message with two bold runs on one line shows both without their markers. Before, the run's optional group was greedy and stretched to the last marker on the line: | Message | Before | After | | --- | --- | --- | | `option **A** or option **B**` | `option A** or option **B` | `option A or option B` | | `~~x~~ and ~~y~~` | `x~~ and ~~y` | `x and y` | | `**😀** and **b**` | `😀** and **b` | `😀 and b` | The fix makes that group lazy (`(?:.*?\S)??`). Found while reviewing the Dart port in [#9556 Dart notification body](https://github.com/block/buzz/pull/9556), which must match these fixtures. That PR takes the same pattern once this one lands. ### Validation - Added tests: three shared rows in `test-fixtures/notification-body.json`, one per row above. All three fail with the old pattern. - All 70 BuzzPushKit tests pass on macOS, including the other 36 fixture rows, which are unchanged. ### Regressions None expected. The pattern still needs non-space characters right inside both markers and still stays on one line. It now stops at the first closing marker where before it reached for the last one. The output changes only where a one-character run is followed by the same marker later on the line, for example `**a** costs 2**3`, which was `a** costs 23` and is now `a costs 2**3`. Worst-case time for unclosed markers is unchanged (measured during review of the Dart port). Signed-off-by: Tom Brow Co-authored-by: Tom Brow --- .../BuzzPushNotificationResolver.swift | 2 +- test-fixtures/notification-body.json | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushNotificationResolver.swift b/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushNotificationResolver.swift index ecc1fbec50..4cca35d1fc 100644 --- a/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushNotificationResolver.swift +++ b/mobile/ios/BuzzPushKit/Sources/BuzzPushKit/BuzzPushNotificationResolver.swift @@ -769,7 +769,7 @@ public final class BuzzPushNotificationResolver: BuzzPushNotificationResolving { .replacingOccurrences( of: #"!?\[([^\]]*)\]\([^)]*\)"#, with: "$1", options: .regularExpression) .replacingOccurrences( - of: #"(\*\*|~~)(\S(?:.*?\S)?)\1"#, with: "$2", options: .regularExpression) + of: #"(\*\*|~~)(\S(?:.*?\S)??)\1"#, with: "$2", options: .regularExpression) .replacingOccurrences(of: #"[ \t]+"#, with: " ", options: .regularExpression) } diff --git a/test-fixtures/notification-body.json b/test-fixtures/notification-body.json index 9ba167c064..a10ab255e2 100644 --- a/test-fixtures/notification-body.json +++ b/test-fixtures/notification-body.json @@ -152,6 +152,21 @@ "input": "**Run `fetch()` now** and ~~`old()`~~", "expected": "Run fetch() now and old()" }, + { + "name": "each bold run ends at its first closing marker", + "input": "option **A** or option **B**", + "expected": "option A or option B" + }, + { + "name": "each strikethrough run ends at its first closing marker", + "input": "~~x~~ and ~~y~~", + "expected": "x and y" + }, + { + "name": "a one-character bold run can be an emoji", + "input": "**😀** and **b**", + "expected": "😀 and b" + }, { "name": "markup inside code stays literal", "input": "Use `**[a](b)**` as is",