Skip to content

Commit f23e5cb

Browse files
author
Mark
committed
fixed URL encoding bug (#97)
1 parent 16e8f73 commit f23e5cb

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

src/main/java/com/arangodb/internal/ArangoExecutor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
*/
4343
public abstract class ArangoExecutor<R, C extends Connection> {
4444

45+
private static final String SLASH = "/";
46+
4547
public static interface ResponseDeserializer<T> {
4648
T deserialize(Response response) throws VPackException;
4749
}
@@ -83,12 +85,12 @@ protected String createPath(final String... params) {
8385
final StringBuilder sb = new StringBuilder();
8486
for (int i = 0; i < params.length; i++) {
8587
if (i > 0) {
86-
sb.append("/");
88+
sb.append(SLASH);
8789
}
8890
try {
8991
final String param;
90-
if (params[i].contains("/") || params[i].contains(" ")) {
91-
param = params[i];
92+
if (params[i].contains(SLASH)) {
93+
param = createPath(params[i].split(SLASH));
9294
} else {
9395
param = URLEncoder.encode(params[i], "UTF-8");
9496
}
@@ -108,6 +110,11 @@ public void validateDocumentId(final String id) throws ArangoDBException {
108110
validateName("document id", REGEX_DOCUMENT_ID, id);
109111
}
110112

113+
public String createDocumentHandle(final String collection, final String key) {
114+
validateDocumentKey(key);
115+
return new StringBuffer().append(collection).append(SLASH).append(key).toString();
116+
}
117+
111118
protected void validateName(final String type, final String regex, final CharSequence name)
112119
throws ArangoDBException {
113120
if (!Pattern.matches(regex, name)) {

src/main/java/com/arangodb/internal/InternalArangoCollection.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ public String name() {
7878
return name;
7979
}
8080

81-
public String createDocumentHandle(final String key) {
82-
executor.validateDocumentKey(key);
83-
return executor.createPath(name, key);
84-
}
85-
8681
protected <T> Request insertDocumentRequest(final T value, final DocumentCreateOptions options) {
8782
final Request request = new Request(db, RequestType.POST,
8883
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, name));
@@ -186,7 +181,7 @@ protected Request importDocumentsRequest(final DocumentImportOptions options) {
186181

187182
protected Request getDocumentRequest(final String key, final DocumentReadOptions options) {
188183
final Request request = new Request(db, RequestType.GET,
189-
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, createDocumentHandle(key)));
184+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
190185
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
191186
request.putHeaderParam(ArangoDBConstants.IF_NONE_MATCH, params.getIfNoneMatch());
192187
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -198,7 +193,7 @@ protected <T> Request replaceDocumentRequest(
198193
final T value,
199194
final DocumentReplaceOptions options) {
200195
final Request request = new Request(db, RequestType.PUT,
201-
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, createDocumentHandle(key)));
196+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
202197
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
203198
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
204199
request.putQueryParam(ArangoDBConstants.IGNORE_REVS, params.getIgnoreRevs());
@@ -290,7 +285,7 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
290285
protected <T> Request updateDocumentRequest(final String key, final T value, final DocumentUpdateOptions options) {
291286
final Request request;
292287
request = new Request(db, RequestType.PATCH,
293-
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, createDocumentHandle(key)));
288+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
294289
final DocumentUpdateOptions params = (options != null ? options : new DocumentUpdateOptions());
295290
request.putQueryParam(ArangoDBConstants.KEEP_NULL, params.getKeepNull());
296291
request.putQueryParam(ArangoDBConstants.MERGE_OBJECTS, params.getMergeObjects());
@@ -384,7 +379,7 @@ public MultiDocumentEntity<DocumentUpdateEntity<T>> deserialize(final Response r
384379
protected Request deleteDocumentRequest(final String key, final DocumentDeleteOptions options) {
385380
final Request request;
386381
request = new Request(db, RequestType.DELETE,
387-
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, createDocumentHandle(key)));
382+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
388383
final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions());
389384
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
390385
request.putQueryParam(ArangoDBConstants.RETURN_OLD, params.getReturnOld());
@@ -453,7 +448,7 @@ public MultiDocumentEntity<DocumentDeleteEntity<T>> deserialize(final Response r
453448
protected Request documentExistsRequest(final String key, final DocumentExistsOptions options) {
454449
final Request request;
455450
request = new Request(db, RequestType.HEAD,
456-
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, createDocumentHandle(key)));
451+
executor.createPath(ArangoDBConstants.PATH_API_DOCUMENT, executor.createDocumentHandle(name, key)));
457452
final DocumentExistsOptions params = (options != null ? options : new DocumentExistsOptions());
458453
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
459454
request.putHeaderParam(ArangoDBConstants.IF_NONE_MATCH, params.getIfNoneMatch());

src/main/java/com/arangodb/internal/InternalArangoEdgeCollection.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public String name() {
6161
return name;
6262
}
6363

64-
protected String createDocumentHandle(final String key) {
65-
executor.validateDocumentKey(key);
66-
return executor.createPath(name, key);
67-
}
68-
6964
protected <T> Request insertEdgeRequest(final T value, final EdgeCreateOptions options) {
7065
final Request request = new Request(db, RequestType.POST,
7166
executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.EDGE, name));
@@ -93,7 +88,7 @@ public EdgeEntity deserialize(final Response response) throws VPackException {
9388

9489
protected Request getEdgeRequest(final String key, final DocumentReadOptions options) {
9590
final Request request = new Request(db, RequestType.GET, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL,
96-
graph, ArangoDBConstants.EDGE, createDocumentHandle(key)));
91+
graph, ArangoDBConstants.EDGE, executor.createDocumentHandle(name, key)));
9792
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
9893
request.putHeaderParam(ArangoDBConstants.IF_NONE_MATCH, params.getIfNoneMatch());
9994
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -111,7 +106,7 @@ public T deserialize(final Response response) throws VPackException {
111106

112107
protected <T> Request replaceEdgeRequest(final String key, final T value, final EdgeReplaceOptions options) {
113108
final Request request = new Request(db, RequestType.PUT, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL,
114-
graph, ArangoDBConstants.EDGE, createDocumentHandle(key)));
109+
graph, ArangoDBConstants.EDGE, executor.createDocumentHandle(name, key)));
115110
final EdgeReplaceOptions params = (options != null ? options : new EdgeReplaceOptions());
116111
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
117112
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -136,7 +131,7 @@ public EdgeUpdateEntity deserialize(final Response response) throws VPackExcepti
136131
protected <T> Request updateEdgeRequest(final String key, final T value, final EdgeUpdateOptions options) {
137132
final Request request;
138133
request = new Request(db, RequestType.PATCH, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph,
139-
ArangoDBConstants.EDGE, createDocumentHandle(key)));
134+
ArangoDBConstants.EDGE, executor.createDocumentHandle(name, key)));
140135
final EdgeUpdateOptions params = (options != null ? options : new EdgeUpdateOptions());
141136
request.putQueryParam(ArangoDBConstants.KEEP_NULL, params.getKeepNull());
142137
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -156,8 +151,9 @@ public EdgeUpdateEntity deserialize(final Response response) throws VPackExcepti
156151
}
157152

158153
protected Request deleteEdgeRequest(final String key, final EdgeDeleteOptions options) {
159-
final Request request = new Request(db, RequestType.DELETE, executor.createPath(
160-
ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.EDGE, createDocumentHandle(key)));
154+
final Request request = new Request(db, RequestType.DELETE,
155+
executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.EDGE,
156+
executor.createDocumentHandle(name, key)));
161157
final EdgeDeleteOptions params = (options != null ? options : new EdgeDeleteOptions());
162158
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
163159
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());

src/main/java/com/arangodb/internal/InternalArangoVertexCollection.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ public String name() {
6161
return name;
6262
}
6363

64-
protected String createDocumentHandle(final String key) {
65-
executor.validateDocumentKey(key);
66-
return executor.createPath(name, key);
67-
}
68-
6964
protected Request dropRequest() {
7065
return new Request(db, RequestType.DELETE,
7166
executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.VERTEX, name));
@@ -98,7 +93,7 @@ public VertexEntity deserialize(final Response response) throws VPackException {
9893

9994
protected Request getVertexRequest(final String key, final DocumentReadOptions options) {
10095
final Request request = new Request(db, RequestType.GET, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL,
101-
graph, ArangoDBConstants.VERTEX, createDocumentHandle(key)));
96+
graph, ArangoDBConstants.VERTEX, executor.createDocumentHandle(name, key)));
10297
final DocumentReadOptions params = (options != null ? options : new DocumentReadOptions());
10398
request.putHeaderParam(ArangoDBConstants.IF_NONE_MATCH, params.getIfNoneMatch());
10499
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -116,7 +111,7 @@ public T deserialize(final Response response) throws VPackException {
116111

117112
protected <T> Request replaceVertexRequest(final String key, final T value, final VertexReplaceOptions options) {
118113
final Request request = new Request(db, RequestType.PUT, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL,
119-
graph, ArangoDBConstants.VERTEX, createDocumentHandle(key)));
114+
graph, ArangoDBConstants.VERTEX, executor.createDocumentHandle(name, key)));
120115
final VertexReplaceOptions params = (options != null ? options : new VertexReplaceOptions());
121116
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
122117
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());
@@ -141,7 +136,7 @@ public VertexUpdateEntity deserialize(final Response response) throws VPackExcep
141136
protected <T> Request updateVertexRequest(final String key, final T value, final VertexUpdateOptions options) {
142137
final Request request;
143138
request = new Request(db, RequestType.PATCH, executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph,
144-
ArangoDBConstants.VERTEX, createDocumentHandle(key)));
139+
ArangoDBConstants.VERTEX, executor.createDocumentHandle(name, key)));
145140
final VertexUpdateOptions params = (options != null ? options : new VertexUpdateOptions());
146141
request.putQueryParam(ArangoDBConstants.KEEP_NULL, params.getKeepNull());
147142
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -161,8 +156,9 @@ public VertexUpdateEntity deserialize(final Response response) throws VPackExcep
161156
}
162157

163158
protected Request deleteVertexRequest(final String key, final VertexDeleteOptions options) {
164-
final Request request = new Request(db, RequestType.DELETE, executor.createPath(
165-
ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.VERTEX, createDocumentHandle(key)));
159+
final Request request = new Request(db, RequestType.DELETE,
160+
executor.createPath(ArangoDBConstants.PATH_API_GHARIAL, graph, ArangoDBConstants.VERTEX,
161+
executor.createDocumentHandle(name, key)));
166162
final VertexDeleteOptions params = (options != null ? options : new VertexDeleteOptions());
167163
request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, params.getWaitForSync());
168164
request.putHeaderParam(ArangoDBConstants.IF_MATCH, params.getIfMatch());

0 commit comments

Comments
 (0)