Skip to content

Commit 11d5c2f

Browse files
committed
internal_links: Add variable realmUrlWithSlash to add '/'
Updates the URL construction to include a trailing slash before the fragment identifier. This ensures that the URL is properly formatted and makes the url linkified. Fixes: #845
1 parent 6979b50 commit 11d5c2f

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lib/model/internal_link.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ Uri narrowLink(PerAccountStore store, Narrow narrow, {int? nearMessageId}) {
9696
fragment.write('/near/$nearMessageId');
9797
}
9898

99-
return store.realmUrl.replace(fragment: fragment.toString());
99+
final realmUrlWithSlash = store.realmUrl.path.endsWith('/')
100+
? store.realmUrl
101+
: store.realmUrl.replace(path: '${store.realmUrl.path}/');
102+
103+
return realmUrlWithSlash.replace(fragment: fragment.toString());
100104
}
101105

102106
/// A [Narrow] from a given URL, on `store`'s realm.

test/widgets/action_sheet_test.dart

+26-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ late FakeApiConnection connection;
3838
Future<void> setupToMessageActionSheet(WidgetTester tester, {
3939
required Message message,
4040
required Narrow narrow,
41+
Account? account,
4142
}) async {
4243
addTearDown(testBinding.reset);
4344

44-
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot());
45-
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
45+
account ??= eg.selfAccount;
46+
final initialSnapshot = eg.initialSnapshot(zulipFeatureLevel: account.zulipFeatureLevel);
47+
await testBinding.globalStore.add(account, initialSnapshot);
48+
final store = await testBinding.globalStore.perAccount(account.id);
4649
await store.addUser(eg.user(userId: message.senderId));
4750
if (message is StreamMessage) {
4851
final stream = eg.stream(streamId: message.streamId);
@@ -60,8 +63,8 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
6063
historyLimited: false,
6164
messages: [message],
6265
).toJson());
63-
64-
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
66+
await tester.pumpAndSettle();
67+
await tester.pumpWidget(TestZulipApp(accountId: account.id,
6568
child: MessageListPage(initNarrow: narrow)));
6669

6770
// global store, per-account store, and message list get loaded
@@ -551,6 +554,24 @@ void main() {
551554
final expectedLink = narrowLink(store, narrow, nearMessageId: message.id).toString();
552555
check(await Clipboard.getData('text/plain')).isNotNull().text.equals(expectedLink);
553556
});
557+
558+
testWidgets('Full Url Testing', (tester) async {
559+
final message = eg.streamMessage();
560+
final narrow = TopicNarrow.ofMessage(message);
561+
await setupToMessageActionSheet(tester, message: message, narrow: narrow);
562+
await tapCopyMessageLinkButton(tester);
563+
await tester.pump(Duration.zero);
564+
565+
final customAccount = eg.selfAccount.copyWith(
566+
id: 2, realmUrl: Uri.parse('https://chat.example'));
567+
await setupToMessageActionSheet(
568+
tester, message: message, narrow: narrow, account: customAccount);
569+
final customAccountStore = await testBinding.globalStore.perAccount(customAccount.id);
570+
final expectedLink = narrowLink(
571+
customAccountStore, narrow, nearMessageId: message.id).toString();
572+
573+
check(await Clipboard.getData('text/plain')).isNotNull().text.equals(expectedLink);
574+
});
554575
});
555576

556577
group('ShareButton', () {
@@ -616,4 +637,4 @@ void main() {
616637
check(mockSharePlus.sharedString).isNull();
617638
});
618639
});
619-
}
640+
}

0 commit comments

Comments
 (0)