@Test public void canonicalizeUrl() throws Exception { assertEquals("http: assertEquals("https: assertEquals("http: service.canonicalizeUrl("http: assertEquals("http: service.canonicalizeUrl("http: assertEquals("foo", service.canonicalizeUrl("foo")); assertEquals("ftp: }
@VisibleForTesting String canonicalizeUrl(String url) { String cleaned = url.replaceAll("[\r\n \t]*", ""); try { URI uri = new URI(cleaned); List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8); List<NameValuePair> cleanedParams = params.stream() .filter(pair -> !pair.getName().startsWith("utm_")) .sorted(Comparator.comparing(NameValuePair::getName) .thenComparing(NameValuePair::getValue)) .collect(toList()); URIBuilder uriBuilder = new URIBuilder(uri); if (cleanedParams.isEmpty()) { uriBuilder.clearParameters(); } else { uriBuilder.setParameters(cleanedParams); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { } return cleaned; }
ArticleServiceImpl implements ArticleService { @VisibleForTesting String canonicalizeUrl(String url) { String cleaned = url.replaceAll("[\r\n \t]*", ""); try { URI uri = new URI(cleaned); List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8); List<NameValuePair> cleanedParams = params.stream() .filter(pair -> !pair.getName().startsWith("utm_")) .sorted(Comparator.comparing(NameValuePair::getName) .thenComparing(NameValuePair::getValue)) .collect(toList()); URIBuilder uriBuilder = new URIBuilder(uri); if (cleanedParams.isEmpty()) { uriBuilder.clearParameters(); } else { uriBuilder.setParameters(cleanedParams); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { } return cleaned; } }
ArticleServiceImpl implements ArticleService { @VisibleForTesting String canonicalizeUrl(String url) { String cleaned = url.replaceAll("[\r\n \t]*", ""); try { URI uri = new URI(cleaned); List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8); List<NameValuePair> cleanedParams = params.stream() .filter(pair -> !pair.getName().startsWith("utm_")) .sorted(Comparator.comparing(NameValuePair::getName) .thenComparing(NameValuePair::getValue)) .collect(toList()); URIBuilder uriBuilder = new URIBuilder(uri); if (cleanedParams.isEmpty()) { uriBuilder.clearParameters(); } else { uriBuilder.setParameters(cleanedParams); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { } return cleaned; }  }
ArticleServiceImpl implements ArticleService { @VisibleForTesting String canonicalizeUrl(String url) { String cleaned = url.replaceAll("[\r\n \t]*", ""); try { URI uri = new URI(cleaned); List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8); List<NameValuePair> cleanedParams = params.stream() .filter(pair -> !pair.getName().startsWith("utm_")) .sorted(Comparator.comparing(NameValuePair::getName) .thenComparing(NameValuePair::getValue)) .collect(toList()); URIBuilder uriBuilder = new URIBuilder(uri); if (cleanedParams.isEmpty()) { uriBuilder.clearParameters(); } else { uriBuilder.setParameters(cleanedParams); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { } return cleaned; }  @Override Article createExternalLink(Authorization authorization,
      Zone zone,
      String title,
      String link); @Override boolean canCreateArticle(Zone zone, Authorization auth); @Override Article createSpeak(Authorization authorization, Zone zone, String title, String content); @Override Optional<Article> findArticle(FlakeId articleId); @Override List<Article> listLatestZoneArticles(Zone zone, @Nullable FlakeId startArticleId); @Override Article loadArticle(FlakeId articleId); @Override String loadEditableDebateContent(FlakeId debateId, Authorization editor); @Override String updateDebateContent(FlakeId debateId, Authorization editorAuth, String content); @Override Debate debate(FlakeId articleId,
      @Nullable FlakeId parentDebateId,
      Authorization debaterAuth,
      String content); @Override DebateTree listBestDebates(FlakeId articleId, @Nullable FlakeId parentDebateId); @Override List<Article> listHotZoneArticles(Zone zone, FlakeId startArticleId); @Override @Cacheable(value = "rssHotArticles") List<Article> listRssHotZoneArticlesWithCache(Zone zone); @Override @Cacheable(value = "rssHotArticles") List<Article> listRssTopArticlesWithCache(); @Override List<Article> listLatestArticles(@Nullable FlakeId startArticleId); @Override List<Article> listTopArticles(@Nullable FlakeId startArticleId); @Override Debate loadDebateWithoutCache(FlakeId debateId); @Override Debate loadDebateWithCache(FlakeId debateId); @Override List<Debate> listReplyToDebates(Authorization authorization,
      @Nullable FlakeId startDebateId); @Override List<Debate> listLatestDebates(@Nullable FlakeId startDebateId); @Override List<Debate> listLatestZoneDebates(Zone zone, @Nullable FlakeId startDebateId); @Override List<Article> listArticlesByDebatesWithCache(List<FlakeId> debateIds); @Override List<Debate> listDebatesByIdWithCache(List<FlakeId> debateIds); @Override List<Article> listArticlesByAuthor(String username, @Nullable FlakeId startArticleId); @Override List<Debate> listDebatesByDebater(String username, @Nullable FlakeId startDebateId); @Override boolean isExternalLinkExist(Zone zone, String externalLink); @Override List<Article> listArticlesByExternalLink(Zone zone, String externalLink); @Override void deleteArticle(Authorization authorization, FlakeId articleId); @Override boolean canDeleteArticle(String username, FlakeId articleId); }
ArticleServiceImpl implements ArticleService { @VisibleForTesting String canonicalizeUrl(String url) { String cleaned = url.replaceAll("[\r\n \t]*", ""); try { URI uri = new URI(cleaned); List<NameValuePair> params = URLEncodedUtils.parse(uri, Charsets.UTF_8); List<NameValuePair> cleanedParams = params.stream() .filter(pair -> !pair.getName().startsWith("utm_")) .sorted(Comparator.comparing(NameValuePair::getName) .thenComparing(NameValuePair::getValue)) .collect(toList()); URIBuilder uriBuilder = new URIBuilder(uri); if (cleanedParams.isEmpty()) { uriBuilder.clearParameters(); } else { uriBuilder.setParameters(cleanedParams); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { } return cleaned; }  @Override Article createExternalLink(Authorization authorization,
      Zone zone,
      String title,
      String link); @Override boolean canCreateArticle(Zone zone, Authorization auth); @Override Article createSpeak(Authorization authorization, Zone zone, String title, String content); @Override Optional<Article> findArticle(FlakeId articleId); @Override List<Article> listLatestZoneArticles(Zone zone, @Nullable FlakeId startArticleId); @Override Article loadArticle(FlakeId articleId); @Override String loadEditableDebateContent(FlakeId debateId, Authorization editor); @Override String updateDebateContent(FlakeId debateId, Authorization editorAuth, String content); @Override Debate debate(FlakeId articleId,
      @Nullable FlakeId parentDebateId,
      Authorization debaterAuth,
      String content); @Override DebateTree listBestDebates(FlakeId articleId, @Nullable FlakeId parentDebateId); @Override List<Article> listHotZoneArticles(Zone zone, FlakeId startArticleId); @Override @Cacheable(value = "rssHotArticles") List<Article> listRssHotZoneArticlesWithCache(Zone zone); @Override @Cacheable(value = "rssHotArticles") List<Article> listRssTopArticlesWithCache(); @Override List<Article> listLatestArticles(@Nullable FlakeId startArticleId); @Override List<Article> listTopArticles(@Nullable FlakeId startArticleId); @Override Debate loadDebateWithoutCache(FlakeId debateId); @Override Debate loadDebateWithCache(FlakeId debateId); @Override List<Debate> listReplyToDebates(Authorization authorization,
      @Nullable FlakeId startDebateId); @Override List<Debate> listLatestDebates(@Nullable FlakeId startDebateId); @Override List<Debate> listLatestZoneDebates(Zone zone, @Nullable FlakeId startDebateId); @Override List<Article> listArticlesByDebatesWithCache(List<FlakeId> debateIds); @Override List<Debate> listDebatesByIdWithCache(List<FlakeId> debateIds); @Override List<Article> listArticlesByAuthor(String username, @Nullable FlakeId startArticleId); @Override List<Debate> listDebatesByDebater(String username, @Nullable FlakeId startDebateId); @Override boolean isExternalLinkExist(Zone zone, String externalLink); @Override List<Article> listArticlesByExternalLink(Zone zone, String externalLink); @Override void deleteArticle(Authorization authorization, FlakeId articleId); @Override boolean canDeleteArticle(String username, FlakeId articleId);  }