Skip to content

Commit 2cd9d5c

Browse files
committed
For open source Parse with /parse mounts, this fix helps avoid the problem of remembering to add
the trailing slash.
1 parent 036b0cb commit 2cd9d5c

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Parse/src/main/java/com/parse/Parse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public Builder clientKey(String clientKey) {
142142
* @return The same builder, for easy chaining.
143143
*/
144144
public Builder server(String server) {
145+
146+
// Add an extra trailing slash so that Parse REST commands include
147+
// the path as part of the server URL (i.e. http://api.myhost.com/parse)
148+
if (server.charAt(server.length() - 1) != '/') {
149+
server = server + "/";
150+
}
151+
145152
this.server = server;
146153
return this;
147154
}

Parse/src/test/java/com/parse/ParseClientConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public void testBuilder() {
3030
Parse.Configuration.Builder builder = new Parse.Configuration.Builder(null);
3131
builder.applicationId("foo");
3232
builder.clientKey("bar");
33-
builder.server("some.server");
33+
builder.server("http://myserver.com/parse");
3434
builder.enableLocalDataStore();
3535
Parse.Configuration configuration = builder.build();
3636

3737
assertNull(configuration.context);
3838
assertEquals(configuration.applicationId, "foo");
3939
assertEquals(configuration.clientKey, "bar");
40-
assertEquals(configuration.server, "some.server");
40+
assertEquals(configuration.server, "http://myserver.com/parse/");
4141
assertEquals(configuration.localDataStoreEnabled, true);
4242
}
4343

Parse/src/test/java/com/parse/ParseRESTCommandTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.ByteArrayInputStream;
2727
import java.io.IOException;
2828
import java.io.InputStream;
29-
import java.net.MalformedURLException;
3029
import java.net.URL;
3130

3231
import bolts.Task;
@@ -91,6 +90,16 @@ public void testInitializationWithDefaultParseServerURL() throws Exception {
9190
assertEquals("https://api.parse.com/1/events/Appopened", command.url);
9291
}
9392

93+
@Test
94+
public void testInitializationWithMissingSlash() throws Exception {
95+
ParseRESTCommand.server = new URL("https://api.parse.com/missingslash");
96+
ParseRESTCommand command = new ParseRESTCommand.Builder()
97+
.httpPath("events/Appopened")
98+
.build();
99+
100+
assertEquals("https://api.parse.com/missingslash/events/Appopened", command.url, command.url);
101+
}
102+
94103
@Test
95104
public void testPermanentFailures() throws Exception {
96105
JSONObject json = new JSONObject();

0 commit comments

Comments
 (0)