Skip to content

Commit 9d79fd6

Browse files
committed
added workaroung for angularjs issue 1463 angular/angular.js#1463 ($oid can also be passed as €oid
removed useless warning message if ref field is null
1 parent 2d8fb4f commit 9d79fd6

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

src/main/java/org/restheart/hal/metadata/Relationship.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,11 @@ private Object getReferenceFieldValue(String referenceField, DBObject data) thro
258258

259259
List<Object> objs = JsonUtils.getPropsFromPath(data, referenceField);
260260

261-
if (objs != null && objs.size() == 1 && objs.get(0) == null)
261+
if (objs == null) {
262+
return null;
263+
} else if (objs.size() == 1 && objs.get(0) == null)
262264
return null;
263265

264-
if (objs == null) {
265-
LOGGER.debug("cound not get the value of the reference field " + referenceField + " from " + data.toString() + "\nThe json path expression resolved to null");
266-
throw new IllegalArgumentException("ref-field json path expression resolved to null");
267-
}
268-
269266
// check that objs are all
270267
if (objs.stream().allMatch(obj -> {
271268
if (obj == null || obj instanceof DBObject) {

src/main/java/org/restheart/handlers/injectors/BodyInjectorHandler.java

+28-12
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
100100
DBObject content;
101101

102102
if (isNotFormData(contentTypes)) { // json or hal+json
103-
final String contentString = ChannelReader.read(exchange.getRequestChannel());
103+
final String contentString = workaroundAngularJSIssue1463(ChannelReader.read(exchange.getRequestChannel()));
104104

105105
try {
106106
content = (DBObject) JSON.parse(contentString);
@@ -142,11 +142,11 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
142142
ResponseHelper.endExchangeWithMessage(exchange, HttpStatus.SC_NOT_ACCEPTABLE, errMsg);
143143
return;
144144
}
145-
145+
146146
File file = data.getFirst(fileFieldName).getFile();
147147

148148
context.setFile(file);
149-
149+
150150
injectContentTypeFromFile(content, file);
151151
}
152152

@@ -171,6 +171,20 @@ public void handleRequest(HttpServerExchange exchange, RequestContext context) t
171171
getNext().handleRequest(exchange, context);
172172
}
173173

174+
/**
175+
* need this to workaroung angularjs issue
176+
* https://github.com/angular/angular.js/issues/1463
177+
*
178+
* @param content
179+
* @return
180+
*/
181+
private static String workaroundAngularJSIssue1463(String contentString) {
182+
if (contentString == null)
183+
return null;
184+
185+
return contentString.replaceAll("\"€oid\" *:", "\"\\$oid\" :");
186+
}
187+
174188
/**
175189
*
176190
* @param contentTypes
@@ -215,22 +229,24 @@ private void filterOutReservedKeys(DBObject content, RequestContext context) {
215229
context.addWarning("the reserved field " + keyToRemove + " was filtered out from the request");
216230
});
217231
}
218-
232+
219233
private void injectContentTypeFromFile(DBObject content, File file) throws IOException {
220-
if (content.get("contentType") != null)
234+
if (content.get("contentType") != null) {
221235
return;
222-
236+
}
237+
223238
String contentType;
224-
225-
if (file == null)
239+
240+
if (file == null) {
226241
return;
227-
else
242+
} else {
228243
contentType = detectMediaType(file);
229-
244+
}
245+
230246
if (content == null && contentType != null) {
231247
content = new BasicDBObject();
232-
}
233-
248+
}
249+
234250
content.put("contentType", contentType);
235251
}
236252

0 commit comments

Comments
 (0)