Skip to content

Commit 3bbd921

Browse files
committed
Merge remote-tracking branch 'pr/1059'
2 parents e677f8d + a198c84 commit 3bbd921

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

lib/model/internal_link.dart

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

99-
return store.realmUrl.replace(fragment: fragment.toString());
99+
Uri result = store.realmUrl.replace(fragment: fragment.toString());
100+
if (result.path.isEmpty) {
101+
// Always ensure that there is a '/' right after the hostname.
102+
// A generated URL without '/' looks odd and does not linkify.
103+
result = result.replace(path: '/');
104+
}
105+
return result;
100106
}
101107

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

test/model/compose_test.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,28 @@ hello
314314
'#narrow/dm/1,2-dm/near/12345',
315315
'#narrow/pm-with/1,2-pm/near/12345');
316316
});
317+
318+
test('normalize links to always include a "/" after hostname', () {
319+
void checkGeneratedLink({required String realmUrl, required String expectedLink}) {
320+
final account = eg.selfAccount.copyWith(realmUrl: Uri.parse(realmUrl));
321+
final store = eg.store(account: account);
322+
check(narrowLink(store, const CombinedFeedNarrow()).toString())
323+
.equals(expectedLink);
324+
}
325+
326+
checkGeneratedLink(
327+
realmUrl: 'http://chat.example.com',
328+
expectedLink: 'http://chat.example.com/#narrow');
329+
checkGeneratedLink(
330+
realmUrl: 'http://chat.example.com/',
331+
expectedLink: 'http://chat.example.com/#narrow');
332+
checkGeneratedLink(
333+
realmUrl: 'http://chat.example.com/path',
334+
expectedLink: 'http://chat.example.com/path#narrow');
335+
checkGeneratedLink(
336+
realmUrl: 'http://chat.example.com/path/',
337+
expectedLink: 'http://chat.example.com/path/#narrow');
338+
});
317339
});
318340

319341
group('mention', () {

test/model/internal_link_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void main() {
5555
}
5656
}
5757

58-
group('parseInternalLink', () {
58+
group('parseInternalLink is-internal', () {
5959
final streams = [
6060
eg.stream(streamId: 1, name: 'check'),
6161
];
@@ -398,7 +398,7 @@ void main() {
398398
});
399399
});
400400

401-
group('parseInternalLink', () {
401+
group('parseInternalLink again', () { // TODO perhaps unify with tests above
402402
group('topic link parsing', () {
403403
final stream = eg.stream(name: "general");
404404

0 commit comments

Comments
 (0)