-
Notifications
You must be signed in to change notification settings - Fork 385
fix(ui): enrich link previews for uppercase URL schemes #2843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xsahil03x
merged 1 commit into
master
from
sahil/flu-625-url-enrichment-fails-for-uppercase-https-in-flutter
Jul 23, 2026
+123
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ages/stream_chat_flutter/test/src/message_input/message_composer_url_enrichment_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // ignore_for_file: lines_longer_than_80_chars | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mocktail/mocktail.dart'; | ||
| import 'package:record/record.dart'; | ||
| import 'package:stream_chat_flutter/stream_chat_flutter.dart'; | ||
|
|
||
| import '../fakes.dart'; | ||
| import '../mocks.dart'; | ||
|
|
||
| void main() { | ||
| group('MessageComposer URL enrichment', () { | ||
| final originalRecordPlatform = RecordPlatform.instance; | ||
| setUp(() => RecordPlatform.instance = FakeRecordPlatform()); | ||
| tearDown(() => RecordPlatform.instance = originalRecordPlatform); | ||
|
|
||
| late MockClient client; | ||
| late MockClientState clientState; | ||
| late MockChannel channel; | ||
| late MockChannelState channelState; | ||
|
|
||
| setUp(() { | ||
| registerFallbackValue(Message()); | ||
|
|
||
| client = MockClient(); | ||
| clientState = MockClientState(); | ||
| channel = MockChannel( | ||
| ownCapabilities: const [ | ||
| ChannelCapability.sendMessage, | ||
| ChannelCapability.sendLinks, | ||
| ], | ||
| ); | ||
| channelState = MockChannelState(); | ||
|
|
||
| when(() => client.state).thenReturn(clientState); | ||
| when(() => clientState.currentUser).thenReturn(OwnUser(id: 'user-id')); | ||
| when(() => clientState.currentUserStream).thenAnswer( | ||
| (_) => Stream.value(OwnUser(id: 'user-id')), | ||
| ); | ||
|
|
||
| when(() => channel.state).thenReturn(channelState); | ||
| when(() => channel.client).thenReturn(client); | ||
| when(channel.getRemainingCooldown).thenReturn(0); | ||
|
|
||
| when(() => client.enrichUrl(any())).thenAnswer( | ||
| (invocation) async => OGAttachmentResponse()..ogScrapeUrl = invocation.positionalArguments.first as String, | ||
| ); | ||
| }); | ||
|
|
||
| Future<Object?> enrichUrlFrom(WidgetTester tester, String text) async { | ||
| // Enrichment runs behind a real-clock debounce, so drive the flow with | ||
| // real timers via runAsync. | ||
| await tester.runAsync(() async { | ||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| home: StreamChat( | ||
| client: client, | ||
| connectivityStream: Stream.value([ConnectivityResult.mobile]), | ||
| child: StreamChannel( | ||
| channel: channel, | ||
| child: Scaffold(body: StreamMessageComposer()), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| await tester.enterText(find.byType(TextField), text); | ||
| await Future<void>.delayed(const Duration(milliseconds: 500)); | ||
| await tester.pumpAndSettle(); | ||
| }); | ||
|
|
||
| return verify(() => client.enrichUrl(captureAny())).captured.single; | ||
| } | ||
|
|
||
| // The scheme (and host) are normalized to lowercase before enriching so a | ||
| // backend that only handles lowercase schemes receives a consistent url. | ||
| // Case-sensitive path and query parts must be preserved as-is. | ||
| final cases = <String, (String, String)>{ | ||
| 'uppercase HTTPS scheme': ('HTTPS://example.com', 'https://example.com'), | ||
| 'uppercase HTTP scheme': ('HTTP://example.com', 'http://example.com'), | ||
| 'mixed-case scheme': ('HtTpS://example.com', 'https://example.com'), | ||
| 'mixed-case host': ('HTTPS://Example.COM', 'https://example.com'), | ||
| 'preserves case-sensitive path and query': ( | ||
| 'HTTPS://example.com/Path?Q=AbC', | ||
| 'https://example.com/Path?Q=AbC', | ||
| ), | ||
| 'uppercase scheme with www and path': ( | ||
| 'HTTPS://www.example.com/foo', | ||
| 'https://www.example.com/foo', | ||
| ), | ||
| 'url embedded in surrounding text': ( | ||
| 'look at HTTPS://example.com now', | ||
| 'https://example.com', | ||
| ), | ||
| 'lowercase https scheme unchanged': ( | ||
| 'https://example.com', | ||
| 'https://example.com', | ||
| ), | ||
| }; | ||
|
|
||
| for (final entry in cases.entries) { | ||
| final (input, expected) = entry.value; | ||
| testWidgets('enriches ${entry.key}', (tester) async { | ||
| expect(await enrichUrlFrom(tester, input), expected); | ||
| }); | ||
| } | ||
| }); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Wouldn't it be possible to end up without an enriched URL, it the
/ogendpoint doesn't return in time before sending the message, or if we send the message before this method fires (350msdebounce).I am curious if maybe the bug report was for that reason 🤔 Because I can see some messages getting enriched even with
HTTPS://prefixThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a possibility. But when i tried reproducing it in the sample app i wasn't able to get any og for a link with uppercase
HTTPS://. One way to solve it is to useurl_enrichmentflag on channel but it will still fail as the backend extracts the url from text and the text will still be with Uppercase letters. So this also needs to be fixed in the backend code in order to work correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I was afraid that we would still see reports of this issue after the fix. But nevertheless, I see no reason to block this PR. But we should probably bring this up with the BE as well.