Skip to content

Commit 0bc2e39

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 5d36977 commit 0bc2e39

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/model/internal_link.dart

Lines changed: 5 additions & 1 deletion
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,21 @@ void main() {
553553
});
554554
});
555555

556+
557+
group('narrowLink URL generation tests', () {
558+
559+
testWidgets('Full Url Testing', (tester) async {
560+
final message = eg.streamMessage();
561+
final narrow = TopicNarrow.ofMessage(message);
562+
await setupToMessageActionSheet(tester, message: message, narrow: narrow);
563+
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
564+
final generatedLink = narrowLink(store, narrow, nearMessageId: message.id).toString();
565+
const expectedPrefix = 'https://chat.example/#narrow/stream/123-stream-123/topic';
566+
final truncatedLink = generatedLink.split('/example').first;
567+
check(truncatedLink).equals(expectedPrefix);
568+
});
569+
});
570+
556571
group('ShareButton', () {
557572
// Tests should call this.
558573
MockSharePlus setupMockSharePlus() {

0 commit comments

Comments
 (0)