Skip to content

Commit c7f336c

Browse files
committed
compose [nfc]: Take a URL string at inlineLink, rather than a Uri object
This way this function is a more faithful wrapper of constructing the actual Markdown syntax. The Markdown will have a URL string, after all, so it's for the best to put this function's caller in control of exactly what string that is.
1 parent 314c83c commit c7f336c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/model/compose.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ String wildcardMention(WildcardMentionOption wildcardOption, {
188188
/// result may be surprising.
189189
///
190190
/// The part between "(" and ")" is just a "link destination" (no "link title").
191-
/// That destination is simply the stringified [destination], if provided.
192-
/// If that has parentheses in it, the result may be surprising.
191+
/// That destination is the string [destination], if provided.
192+
/// If [destination] has parentheses in it, the result may be surprising.
193193
// TODO: Try harder to guarantee output that creates an inline link,
194194
// and in particular, the intended one. We could help with this by escaping
195195
// square brackets, perhaps with HTML character references:
@@ -199,8 +199,8 @@ String wildcardMention(WildcardMentionOption wildcardOption, {
199199
// > Backtick code spans, autolinks, and raw HTML tags bind more tightly
200200
// > than the brackets in link text. Thus, for example, [foo`]` could not be
201201
// > a link text, since the second ] is part of a code span.
202-
String inlineLink(String visibleText, Uri? destination) {
203-
return '[$visibleText](${destination?.toString() ?? ''})';
202+
String inlineLink(String visibleText, String? destination) {
203+
return '[$visibleText](${destination ?? ''})';
204204
}
205205

206206
/// What we show while fetching the target message's raw Markdown.
@@ -213,7 +213,7 @@ String quoteAndReplyPlaceholder(
213213
SendableNarrow.ofMessage(message, selfUserId: store.selfUserId),
214214
nearMessageId: message.id);
215215
return '${userMentionFromMessage(message, silent: true, users: store)} '
216-
'${inlineLink('said', url)}: ' // TODO(#1285)
216+
'${inlineLink('said', url.toString())}: ' // TODO(#1285)
217217
'*${zulipLocalizations.composeBoxLoadingMessage(message.id)}*\n';
218218
}
219219

@@ -237,6 +237,6 @@ String quoteAndReply(PerAccountStore store, {
237237
// and the extra noise won't much matter with the already probably-long
238238
// message link in there too.
239239
return '${userMentionFromMessage(message, silent: true, users: store)} '
240-
'${inlineLink('said', url)}:\n' // TODO(#1285)
240+
'${inlineLink('said', url.toString())}:\n' // TODO(#1285)
241241
'${wrapWithBacktickFence(content: rawContent, infoString: 'quote')}';
242242
}

lib/widgets/compose_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ class ComposeContentController extends ComposeController<ContentValidationError>
372372

373373
value = value.replaced(
374374
replacementRange,
375-
url == null ? '' : inlineLink(filename, url));
375+
url == null ? '' : inlineLink(filename, url.toString()));
376376
_uploads.remove(tag);
377377
notifyListeners(); // _uploads change could affect validationErrors
378378
}

test/model/compose_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ hello
319319
});
320320

321321
test('inlineLink', () {
322-
check(inlineLink('CZO', Uri.parse('https://chat.zulip.org/'))).equals('[CZO](https://chat.zulip.org/)');
322+
check(inlineLink('CZO', 'https://chat.zulip.org/')).equals('[CZO](https://chat.zulip.org/)');
323323
check(inlineLink('Uploading file.txt…', null)).equals('[Uploading file.txt…]()');
324-
check(inlineLink('IMG_2488.png', Uri.parse('/user_uploads/2/a3/ucEMyjxk90mcNF0y9rmW5XKO/IMG_2488.png')))
324+
check(inlineLink('IMG_2488.png', '/user_uploads/2/a3/ucEMyjxk90mcNF0y9rmW5XKO/IMG_2488.png'))
325325
.equals('[IMG_2488.png](/user_uploads/2/a3/ucEMyjxk90mcNF0y9rmW5XKO/IMG_2488.png)');
326326
});
327327

0 commit comments

Comments
 (0)