### Question:
MarkwonBasedMarkdownRenderer implements Markdown { @VisibleForTesting String escapeSpacesInLinkUrls(String markdown) { try { Matcher matcher = LINK_MARKDOWN_PATTERN.matcher(markdown); while (matcher.find()) { String linkText = matcher.group(1); String linkUrl = matcher.group(2).replaceAll("\\s", "%20"); markdown = markdown.substring(0, matcher.start()) + String.format("[%s](%s)", linkText, linkUrl) + markdown.substring(matcher.end(), markdown.length()); } } catch (Throwable e) { Timber.e(e, "Couldn't escape spaces in link url in: %s", markdown); } return markdown; } @Inject  MarkwonBasedMarkdownRenderer(
      SpannableConfiguration configuration,
      AutoRedditLinkExtension autoRedditLinkExtension,
      EmptyListItemHandlerExtension emptyListItemHandlerExtension,
      MarkdownHintOptions markdownOptions,
      @Named("markwon_spans_renderer") Cache<String, CharSequence> cache); @Override CharSequence parse(PendingSyncReply reply); @Override CharSequence parseAuthorFlair(String flair); @Override CharSequence parse(Message message); @Override CharSequence parse(Comment comment); @Override CharSequence parseSelfText(Submission submission); @Override @Deprecated String stripMarkdown(Comment comment); @Override String stripMarkdown(Message message); @Override void clearCache();  }### Answer:
@Test public void escapeSpacesInLinkUrls() { String invalid = "see [Wikipedia](http: "[Spoiler](/s)\n\n*****\n\nSub: /r/pics r/pics\n\nUser: /u/Saketme/ u/saketme/\n\n*****\n\n[^Send ^feedback](https: "/message/compose/?to=poochi&amp;amp;subject=New bot feedback)\n\n[spoiler](/s \"the right thing :p\")\n\n[spoiler](#s \"I will be " + "hanged\")\n\nEdit: fixed grammar"; String expected = "see [Wikipedia](http: "\n" + "[Spoiler](/s \"text inside quotes\") [Spoiler](/s \"\") [Spoiler](/s)\n" + "\n" + "*****\n" + "\n" + "Sub: /r/pics r/pics\n" + "\n" + "User: /u/Saketme/ u/saketme/\n" + "\n" + "*****\n" + "\n" + "[^Send ^feedback](https: "\n[spoiler](/s \"the right thing :p\")\n\n[spoiler](#s \"I will be hanged\")\n\nEdit: fixed grammar"; String parsed = renderer.escapeSpacesInLinkUrls(invalid); assertEquals(expected, parsed); }