summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2011-05-27 15:51:03 -0700
committerShawn O. Pearce <sop@google.com>2011-05-27 15:51:03 -0700
commitb645c639fc01197bc23b050898d483ce8d98a293 (patch)
treebf930948d558544d2cc4c558819545fbc90b93f5
parent7f84ef2379f5882316f57df4eca60eaf9e7683bd (diff)
parent1f412fe330e65ac25e9577947eb2d00582c335b6 (diff)
Merge branch 'stable'
* stable: Escape spaces in HTTP URLs during replication Invert signed-in and signed-out background colors
-rw-r--r--Documentation/config-gerrit.txt4
-rw-r--r--gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java4
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/git/PushReplication.java30
-rw-r--r--gerrit-server/src/test/java/com/google/gerrit/server/git/PushReplicationTest.java42
4 files changed, 74 insertions, 6 deletions
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 39eb057a56..cec2783976 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -1810,8 +1810,8 @@ Background color for the page, and major data tables like the all
open changes table or the account dashboard. The value must be a
valid HTML hex color code, or standard color name.
+
-By default white, `FFFFFF` for signed-out theme and `FCFEEF` (creme)
-for signed-in theme.
+By default `FCFEEF` (a creme color) for signed-out theme and white
+(`FFFFFF`) for signed-in theme.
[[theme.topMenuColor]]theme.topMenuColor::
+
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java
index a1e09f9861..68379d765e 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java
@@ -38,7 +38,7 @@ class ThemeFactory {
private HostPageData.Theme getTheme(String name) {
HostPageData.Theme theme = new HostPageData.Theme();
- theme.backgroundColor = color(name, "backgroundColor", "#FFFFFF");
+ theme.backgroundColor = color(name, "backgroundColor", "#FCFEEF");
theme.textColor = color(name, "textColor", "#000000");
theme.trimColor = color(name, "trimColor", "#D4E9A9");
theme.selectionColor = color(name, "selectionColor", "#FFFFCC");
@@ -52,7 +52,7 @@ class ThemeFactory {
v = cfg.getString("theme", null, name);
if (v == null || v.isEmpty()) {
if ("signed-in".equals(section) && "backgroundColor".equals(name)) {
- v = "#FCFEEF";
+ v = "#FFFFFF";
} else {
v = defaultValue;
}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/PushReplication.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/PushReplication.java
index 295a143713..cb005aa6da 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/PushReplication.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/PushReplication.java
@@ -50,7 +50,9 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -531,8 +533,11 @@ public class PushReplication implements ReplicationQueue {
final List<URIish> r = new ArrayList<URIish>(remote.getURIs().size());
for (URIish uri : remote.getURIs()) {
if (matches(uri, urlMatch)) {
- final String replacedPath =
- replace(uri.getPath(), "name", project.get());
+ String name = project.get();
+ if (needsUrlEncoding(uri)) {
+ name = encode(name);
+ }
+ String replacedPath = replace(uri.getPath(), "name", name);
if (replacedPath != null) {
uri = uri.setPath(replacedPath);
r.add(uri);
@@ -542,6 +547,27 @@ public class PushReplication implements ReplicationQueue {
return r;
}
+ static boolean needsUrlEncoding(URIish uri) {
+ return "http".equalsIgnoreCase(uri.getScheme())
+ || "https".equalsIgnoreCase(uri.getScheme())
+ || "amazon-s3".equalsIgnoreCase(uri.getScheme());
+ }
+
+ static String encode(String str) {
+ try {
+ // Some cleanup is required. The '/' character is always encoded as %2F
+ // however remote servers will expect it to be not encoded as part of the
+ // path used to the repository. Space is incorrectly encoded as '+' for this
+ // context. In the path part of a URI space should be %20, but in form data
+ // space is '+'. Our cleanup replace fixes these two issues.
+ return URLEncoder.encode(str, "UTF-8")
+ .replaceAll("%2[fF]", "/")
+ .replace("+", "%20");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
String[] getAdminUrls() {
return this.adminUrls;
}
diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/git/PushReplicationTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/git/PushReplicationTest.java
new file mode 100644
index 0000000000..b95c7dac87
--- /dev/null
+++ b/gerrit-server/src/test/java/com/google/gerrit/server/git/PushReplicationTest.java
@@ -0,0 +1,42 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.git;
+
+import static com.google.gerrit.server.git.PushReplication.ReplicationConfig.*;
+import junit.framework.TestCase;
+
+import org.eclipse.jgit.transport.URIish;
+
+import java.net.URISyntaxException;
+
+public class PushReplicationTest extends TestCase {
+ public void testNeedsUrlEncoding() throws URISyntaxException {
+ assertTrue(needsUrlEncoding(new URIish("http://host/path")));
+ assertTrue(needsUrlEncoding(new URIish("https://host/path")));
+ assertTrue(needsUrlEncoding(new URIish("amazon-s3://config/bucket/path")));
+
+ assertFalse(needsUrlEncoding(new URIish("host:path")));
+ assertFalse(needsUrlEncoding(new URIish("user@host:path")));
+ assertFalse(needsUrlEncoding(new URIish("git://host/path")));
+ assertFalse(needsUrlEncoding(new URIish("ssh://host/path")));
+ }
+
+ public void testUrlEncoding() {
+ assertEquals("foo/bar/thing", encode("foo/bar/thing"));
+ assertEquals("--%20All%20Projects%20--", encode("-- All Projects --"));
+ assertEquals("name/with%20a%20space", encode("name/with a space"));
+ assertEquals("name%0Awith-LF", encode("name\nwith-LF"));
+ }
+}