From: James Moger Date: Fri, 7 Dec 2012 13:24:43 +0000 (-0500) Subject: Harden metrics from polluted data (issue-176) X-Git-Tag: v1.2.0~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ac7e9a61460554aa0183c677bb15d1f473519f55;p=gitblit.git Harden metrics from polluted data (issue-176) --- diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index 396b2550..d42152f9 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -12,6 +12,7 @@ The permissions model has changed in this release. #### fixes +- Author metrics can be broken by newlines in email addresses from converted repositories (issue 176) - Set subjectAlternativeName on generated SSL cert if CN is an ip address (issue 170) - Fixed incorrect links on history page for files not in the current/active commit (issue 166) - Empty repository page failed to handle missing repository (issue 160) diff --git a/src/com/gitblit/models/Activity.java b/src/com/gitblit/models/Activity.java index 771c8a1a..7e0cb4b3 100644 --- a/src/com/gitblit/models/Activity.java +++ b/src/com/gitblit/models/Activity.java @@ -28,6 +28,7 @@ import java.util.Set; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.revwalk.RevCommit; +import com.gitblit.utils.StringUtils; import com.gitblit.utils.TimeUtils; /** @@ -93,8 +94,7 @@ public class Activity implements Serializable, Comparable { } repositoryMetrics.get(repository).count++; - String author = commit.getAuthorIdent().getEmailAddress() - .toLowerCase(); + String author = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase(); if (!authorMetrics.containsKey(author)) { authorMetrics.put(author, new Metric(author)); } diff --git a/src/com/gitblit/utils/MetricUtils.java b/src/com/gitblit/utils/MetricUtils.java index e9e1fa52..26e4581c 100644 --- a/src/com/gitblit/utils/MetricUtils.java +++ b/src/com/gitblit/utils/MetricUtils.java @@ -210,6 +210,7 @@ public class MetricUtils { p = rev.getAuthorIdent().getEmailAddress().toLowerCase(); } } + p = p.replace('\n',' ').replace('\r', ' ').trim(); if (!metricMap.containsKey(p)) { metricMap.put(p, new Metric(p)); } diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index 86840048..86823db5 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -719,4 +719,18 @@ public class StringUtils { Matcher m = p.matcher(input); return m.matches(); } + + /** + * Removes new line and carriage return chars from a string. + * If input value is null an empty string is returned. + * + * @param input + * @return a sanitized or empty string + */ + public static String removeNewlines(String input) { + if (input == null) { + return ""; + } + return input.replace('\n',' ').replace('\r', ' ').trim(); + } } \ No newline at end of file diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.java b/src/com/gitblit/wicket/pages/RepositoryPage.java index b4e1a0e3..897e2001 100644 --- a/src/com/gitblit/wicket/pages/RepositoryPage.java +++ b/src/com/gitblit/wicket/pages/RepositoryPage.java @@ -450,6 +450,8 @@ public abstract class RepositoryPage extends BasePage { Constants.SearchType searchType) { String name = identity == null ? "" : identity.getName(); String address = identity == null ? "" : identity.getEmailAddress(); + name = StringUtils.removeNewlines(name); + address = StringUtils.removeNewlines(address); boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false); if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) { String value = name;