aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-06-18 18:27:45 +0200
committerThomas Wolf <thomas.wolf@paranor.ch>2020-07-08 09:28:29 +0200
commit9b033a1b6da1193dbedca80c217af748ae546629 (patch)
tree64db0be972784732255fd960e01b265b2a44e926 /org.eclipse.jgit
parent0b9370bec83739afa6dfe68241964d80eec36b43 (diff)
downloadjgit-9b033a1b6da1193dbedca80c217af748ae546629.tar.gz
jgit-9b033a1b6da1193dbedca80c217af748ae546629.zip
Fix writing GPG signatures with trailing newline
Make sure we don't produce a spurious empty line at the end. Bug: 564428 Change-Id: Ib991d93fbd052baca65d32a7842f07f9ddeb8130 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java20
1 files changed, 12 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
index 66d7d51bdf..4f93fda49f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
@@ -361,7 +361,9 @@ public class CommitBuilder {
* header</a>.
* <p>
* CRLF and CR will be sanitized to LF and signature will have a hanging
- * indent of one space starting with line two.
+ * indent of one space starting with line two. A trailing line break is
+ * <em>not</em> written; the caller is supposed to terminate the GPG
+ * signature header by writing a single newline.
* </p>
*
* @param in
@@ -375,22 +377,24 @@ public class CommitBuilder {
*/
static void writeGpgSignatureString(String in, OutputStream out)
throws IOException, IllegalArgumentException {
- for (int i = 0; i < in.length(); ++i) {
+ int length = in.length();
+ for (int i = 0; i < length; ++i) {
char ch = in.charAt(i);
switch (ch) {
case '\r':
- if (i + 1 < in.length() && in.charAt(i + 1) == '\n') {
- out.write('\n');
- out.write(' ');
+ if (i + 1 < length && in.charAt(i + 1) == '\n') {
++i;
- } else {
+ }
+ if (i + 1 < length) {
out.write('\n');
out.write(' ');
}
break;
case '\n':
- out.write('\n');
- out.write(' ');
+ if (i + 1 < length) {
+ out.write('\n');
+ out.write(' ');
+ }
break;
default:
// sanity check