mirror of
https://github.com/block/buzz.git
synced 2026-11-08 02:11:36 +00:00
Follow-up to [#8925](https://github.com/block/buzz/pull/8925), from a [Codex finding](https://github.com/block/buzz/pull/8925#discussion_r4446048706) there. After #8925, message Markdown arrives with backslash escapes shielded, but imeta is keyed by plain URLs. Two lookups used the raw, still-escaped destination: - **Bubble segmentation** (`bubble_segments.dart`): an attachment link such as `[voice.mp4](https://…/voice\_note.mp4)` missed its imeta entry and stayed inside the text bubble, even though the link builder rendered it as an attachment. The fix unshields the URL before the lookup. - **Trailing image gallery** (`extractTrailingImageGallery` in `message_gallery.dart`): with two or more trailing images, an escaped destination kept its backslash, so the carousel loaded the wrong URL and lost the imeta alt text. The fix unescapes the destination the same way as the label beside it. Its callers in `message_media_avatar.dart` and `message_skeleton_body.dart` get the fix too. This gap was already on main. ### Validation - The existing `attachments stay outside bubbles and text order is preserved` journey now uses an escaped destination with a plain imeta URL. The existing carousel journey now has one escaped image destination and taps it by its plain URL. Each fails with its fix reverted. - `flutter analyze` is clean and the full mobile suite passes (4151 tests). - Limitation: no simulator run. Both changes are key lookups, and the widget journeys exercise the rendered layout. The full-app run for the surrounding escape handling is recorded in #8925. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.0 KiB
Dart
62 lines
2.0 KiB
Dart
import '../message_media.dart';
|
|
import 'markdown_escapes.dart';
|
|
|
|
/// Splits top-level media from text without breaking Markdown blocks.
|
|
/// Fenced code, lists and quotes retain their nested content.
|
|
List<({String text, bool attachment})> messageBubbleSegments(
|
|
String content,
|
|
Map<String, ImetaEntry> imeta,
|
|
) {
|
|
final result = <({String text, bool attachment})>[];
|
|
final lines = <String>[];
|
|
bool? attachment;
|
|
String? fence;
|
|
var nestedBlock = false;
|
|
final embed = RegExp(r'^!?\[[^\]]*\]\((https?://[^)\s]+)\)$');
|
|
void flush() {
|
|
final text = lines.join('\n').trimRight();
|
|
if (text.trim().isNotEmpty) {
|
|
result.add((text: text, attachment: attachment ?? false));
|
|
}
|
|
lines.clear();
|
|
}
|
|
|
|
for (final line in content.split('\n')) {
|
|
final trimmed = line.trimLeft();
|
|
final marker = RegExp(r'^(`{3,}|~{3,})').firstMatch(trimmed)?.group(1);
|
|
final inFence = fence != null || marker != null || line.startsWith(' ');
|
|
if (marker != null) {
|
|
if (fence == null) {
|
|
fence = marker;
|
|
} else if (marker[0] == fence[0] && marker.length >= fence.length) {
|
|
fence = null;
|
|
}
|
|
}
|
|
if (trimmed.isEmpty) {
|
|
nestedBlock = false;
|
|
} else if (RegExp(r'^(?:>|[-+*]\s|\d+[.)]\s)').hasMatch(trimmed)) {
|
|
nestedBlock = true;
|
|
}
|
|
// Indented embeds belong to a list, quote or code block. Lazy block
|
|
// continuations also stay together until a blank line ends the block.
|
|
final topLevel = line == trimmed && !nestedBlock;
|
|
final match = inFence || !topLevel
|
|
? null
|
|
: embed.firstMatch(line.trimRight());
|
|
final isAttachment =
|
|
match != null &&
|
|
(line.trim().startsWith('!') ||
|
|
// Content arrives with escapes shielded; imeta keys are plain.
|
|
imeta.containsKey(unshieldMarkdownEscapes(match.group(1)!)));
|
|
if (attachment != null &&
|
|
isAttachment != attachment &&
|
|
line.trim().isNotEmpty) {
|
|
flush();
|
|
}
|
|
if (line.trim().isNotEmpty) attachment = isAttachment;
|
|
lines.add(line);
|
|
}
|
|
flush();
|
|
return result;
|
|
}
|