]> source.dussan.org Git - jgit.git/commitdiff
Trim author/committer name and email in commit header 13/38913/1
authorRüdiger Herrmann <ruediger.herrmann@gmx.de>
Fri, 17 Oct 2014 11:05:41 +0000 (13:05 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 2 Jan 2015 23:28:15 +0000 (00:28 +0100)
C Git trims name and email before inserting them into the commit header
so that " A U Thor  " and "  author@example.com " becomes
"A U Thor <author@example.com>" with a single separating space.

This changes PersonIdent#toExternalString() to trim name and email
before concatenating them.

Change-Id: Idd77b659d0db957626824f6632e2da38d7731625
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java

index 1b7276bf77b167ec9c25f34eeea826d646f54e4d..315c495606e3ce1e1d05c98310447b37c2bcfd78 100644 (file)
@@ -44,6 +44,7 @@
 package org.eclipse.jgit.lib;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Date;
 import java.util.TimeZone;
@@ -83,4 +84,15 @@ public class T0001_PersonIdentTest {
        public void nullForEmailShouldThrowIllegalArgumentException() {
                new PersonIdent("A U Thor", null);
        }
+
+       @Test
+       public void testToExternalStringTrimsNameAndEmail() throws Exception {
+               PersonIdent personIdent = new PersonIdent("  A U Thor  ",
+                               "  author@example.com  ");
+
+               String externalString = personIdent.toExternalString();
+
+               assertTrue(externalString.startsWith("A U Thor <author@example.com>"));
+       }
+
 }
index 69f7fd4404aed3bc6fe4c10443ff695646a63be6..8f7e3eff7c67279063f304f2b74ede36ebe01e49 100644 (file)
@@ -254,9 +254,9 @@ public class PersonIdent implements Serializable {
         */
        public String toExternalString() {
                final StringBuilder r = new StringBuilder();
-               r.append(getName());
+               r.append(getName().trim());
                r.append(" <"); //$NON-NLS-1$
-               r.append(getEmailAddress());
+               r.append(getEmailAddress().trim());
                r.append("> "); //$NON-NLS-1$
                r.append(when / 1000);
                r.append(' ');