James Moger
2012-12-07 ac7e9a61460554aa0183c677bb15d1f473519f55
Harden metrics from polluted data (issue-176)
5 files modified
22 ■■■■■ changed files
docs/04_releases.mkd 1 ●●●● patch | view | raw | blame | history
src/com/gitblit/models/Activity.java 4 ●●●● patch | view | raw | blame | history
src/com/gitblit/utils/MetricUtils.java 1 ●●●● patch | view | raw | blame | history
src/com/gitblit/utils/StringUtils.java 14 ●●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/RepositoryPage.java 2 ●●●●● patch | view | raw | blame | history
docs/04_releases.mkd
@@ -12,6 +12,7 @@
#### 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)
src/com/gitblit/models/Activity.java
@@ -28,6 +28,7 @@
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 @@
            }
            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));
            }
src/com/gitblit/utils/MetricUtils.java
@@ -210,6 +210,7 @@
                            p = rev.getAuthorIdent().getEmailAddress().toLowerCase();
                        }
                    }
                    p = p.replace('\n',' ').replace('\r',  ' ').trim();
                    if (!metricMap.containsKey(p)) {
                        metricMap.put(p, new Metric(p));
                    }
src/com/gitblit/utils/StringUtils.java
@@ -719,4 +719,18 @@
        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();
    }
}
src/com/gitblit/wicket/pages/RepositoryPage.java
@@ -450,6 +450,8 @@
            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;