]> source.dussan.org Git - gitblit.git/commitdiff
Harden metrics from polluted data (issue-176)
authorJames Moger <james.moger@gitblit.com>
Fri, 7 Dec 2012 13:24:43 +0000 (08:24 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 7 Dec 2012 13:24:43 +0000 (08:24 -0500)
docs/04_releases.mkd
src/com/gitblit/models/Activity.java
src/com/gitblit/utils/MetricUtils.java
src/com/gitblit/utils/StringUtils.java
src/com/gitblit/wicket/pages/RepositoryPage.java

index 396b25503ac8c3cc8c936e3bd463bb0026301255..d42152f9a4885b3d6b372c7fe7dfbc5c9d12ac9d 100644 (file)
@@ -12,6 +12,7 @@ The permissions model has changed in this release.
 \r
 #### fixes\r
 \r
+- Author metrics can be broken by newlines in email addresses from converted repositories (issue 176)\r
 - Set subjectAlternativeName on generated SSL cert if CN is an ip address (issue 170)\r
 - Fixed incorrect links on history page for files not in the current/active commit (issue 166)\r
 - Empty repository page failed to handle missing repository (issue 160)\r
index 771c8a1ab456331136a1ae177aa59f08c375c9b7..7e0cb4b34b7c43c4fb121207e419cbbce5f60cd6 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.eclipse.jgit.lib.PersonIdent;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.utils.StringUtils;\r
 import com.gitblit.utils.TimeUtils;\r
 \r
 /**\r
@@ -93,8 +94,7 @@ public class Activity implements Serializable, Comparable<Activity> {
                        }\r
                        repositoryMetrics.get(repository).count++;\r
 \r
-                       String author = commit.getAuthorIdent().getEmailAddress()\r
-                                       .toLowerCase();\r
+                       String author = StringUtils.removeNewlines(commit.getAuthorIdent().getEmailAddress()).toLowerCase();                    \r
                        if (!authorMetrics.containsKey(author)) {\r
                                authorMetrics.put(author, new Metric(author));\r
                        }\r
index e9e1fa5289e584a8c22de87a66ea6f8f477a2dc3..26e4581c0afe5ffe32f41edab847bdf68a680c36 100644 (file)
@@ -210,6 +210,7 @@ public class MetricUtils {
                                                        p = rev.getAuthorIdent().getEmailAddress().toLowerCase();\r
                                                }\r
                                        }\r
+                                       p = p.replace('\n',' ').replace('\r',  ' ').trim();\r
                                        if (!metricMap.containsKey(p)) {\r
                                                metricMap.put(p, new Metric(p));\r
                                        }\r
index 868400486a6aade2db33fa1f88f9ff5c2f39fb45..86823db5cc5a854fd24308a09795f5c39a5554c4 100644 (file)
@@ -719,4 +719,18 @@ public class StringUtils {
                Matcher m = p.matcher(input);\r
                return m.matches();\r
        }\r
+       \r
+       /**\r
+        * Removes new line and carriage return chars from a string.\r
+        * If input value is null an empty string is returned.\r
+        *  \r
+        * @param input\r
+        * @return a sanitized or empty string\r
+        */\r
+       public static String removeNewlines(String input) {\r
+               if (input == null) {\r
+                       return "";\r
+               }\r
+               return input.replace('\n',' ').replace('\r',  ' ').trim();\r
+       }\r
 }
\ No newline at end of file
index b4e1a0e30b7524528ef3fe1623e61d1734986e65..897e20013d3f6333fee69326b2b7a4d7e9106fe5 100644 (file)
@@ -450,6 +450,8 @@ public abstract class RepositoryPage extends BasePage {
                        Constants.SearchType searchType) {\r
                String name = identity == null ? "" : identity.getName();\r
                String address = identity == null ? "" : identity.getEmailAddress();\r
+               name = StringUtils.removeNewlines(name);\r
+               address = StringUtils.removeNewlines(address);\r
                boolean showEmail = GitBlit.getBoolean(Keys.web.showEmailAddresses, false);\r
                if (!showEmail || StringUtils.isEmpty(name) || StringUtils.isEmpty(address)) {\r
                        String value = name;\r