Skip to content

Commit 541de43

Browse files
committed
Merge pull request skyscreamer#8 from hertzsprung/lenient-recurse-bug
Bug in recursive comparison
2 parents b4513d8 + 64d735f commit 541de43

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/org/skyscreamer/jsonassert/JSONCompare.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ private static void recursivelyCompareJSONArray(String key, JSONArray expected,
226226
continue;
227227
}
228228
if (actualElement instanceof JSONObject) {
229-
if (compareJSON((JSONObject)actualElement, (JSONObject)expected.get(j), mode).passed()) {
229+
if (compareJSON((JSONObject)expected.get(j), (JSONObject)actualElement, mode).passed()) {
230230
matched.add(j);
231231
matchFound = true;
232232
break;
233233
}
234234
}
235235
else if (actualElement instanceof JSONArray) {
236-
if (compareJSON((JSONArray)actualElement, (JSONArray)expected.get(j), mode).passed()) {
236+
if (compareJSON((JSONArray)expected.get(j), (JSONArray)actualElement, mode).passed()) {
237237
matched.add(j);
238238
matchFound = true;
239239
break;

src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ public void testArrayOfArrays() throws JSONException {
137137
}
138138

139139
@Test
140+
public void testLenientArrayRecursion() throws JSONException {
141+
testPass("[{\"arr\":[5, 2, 1]}]", "[{\"b\":3, \"arr\":[1, 5, 2]}]", false);
142+
}
143+
144+
@Test
140145
public void testFieldMismatch() throws JSONException {
141146
JSONCompareResult result = JSONCompare.compareJSON("{name:\"Pat\"}", "{name:\"Sue\"}", STRICT);
142147
Assert.assertEquals("Pat", result.getExpected());

0 commit comments

Comments
 (0)