summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2012-12-07 08:24:43 -0500
committerJames Moger <james.moger@gitblit.com>2012-12-07 08:24:43 -0500
commitac7e9a61460554aa0183c677bb15d1f473519f55 (patch)
tree7be13095f8b4e04b810cbc7af9d7b1444b09b432
parentdab13a996adbfbc4086be6ff96836e590f7d339c (diff)
downloadgitblit-ac7e9a61460554aa0183c677bb15d1f473519f55.tar.gz
gitblit-ac7e9a61460554aa0183c677bb15d1f473519f55.zip
Harden metrics from polluted data (issue-176)
-rw-r--r--docs/04_releases.mkd1
-rw-r--r--src/com/gitblit/models/Activity.java4
-rw-r--r--src/com/gitblit/utils/MetricUtils.java1
-rw-r--r--src/com/gitblit/utils/StringUtils.java14
-rw-r--r--src/com/gitblit/wicket/pages/RepositoryPage.java2
5 files changed, 20 insertions, 2 deletions
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<Activity> {
}
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;