Browse Source

Strip "<", ">", and "\n" from name/email in UserConfig

This matches what C Git does, see "stripped" in `man git-commit-tree`.

It also fixes the bug of the user where an user.email like "<>" would
show up as "<<>>" in EGit.

Bug: 439844
Change-Id: I567a3c620e191ce9d37d318417e63cb5d4483419
Signed-off-by: Robin Stocker <robin@nibor.org>
tags/v3.5.0.201409071800-rc1
Robin Stocker 9 years ago
parent
commit
ce312d8afb

+ 14
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java View File

assertFalse(localConfig.get(UserConfig.KEY).isCommitterEmailImplicit()); assertFalse(localConfig.get(UserConfig.KEY).isCommitterEmailImplicit());
} }


@Test
public void testReadUserConfigWithInvalidCharactersStripped() {
final MockSystemReader mockSystemReader = new MockSystemReader();
final Config localConfig = new Config(mockSystemReader.openUserConfig(
null, FS.DETECTED));

localConfig.setString("user", null, "name", "foo<bar");
localConfig.setString("user", null, "email", "baz>\nqux@example.com");

UserConfig userConfig = localConfig.get(UserConfig.KEY);
assertEquals("foobar", userConfig.getAuthorName());
assertEquals("bazqux@example.com", userConfig.getAuthorEmail());
}

@Test @Test
public void testReadBoolean_TrueFalse1() throws ConfigInvalidException { public void testReadBoolean_TrueFalse1() throws ConfigInvalidException {
final Config c = parse("[s]\na = true\nb = false\n"); final Config c = parse("[s]\na = true\nb = false\n");

+ 6
- 2
org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java View File

username = system().getenv(envKey); username = system().getenv(envKey);
} }


return username;
return stripInvalidCharacters(username);
} }


/** /**
email = system().getenv(envKey); email = system().getenv(envKey);
} }


return email;
return stripInvalidCharacters(email);
}

private static String stripInvalidCharacters(String s) {
return s == null ? null : s.replaceAll("<|>|\n", ""); //$NON-NLS-1$//$NON-NLS-2$
} }


/** /**

Loading…
Cancel
Save