nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: alibaba/fastjson2
Pull request #3221 (2024-12-26 10:08:02)

BugFix: 修复JSONWriterUTF8.writeStringEscaped申请数组长度不够问题
int minCapacity = off + values.length * 4 + 2;
修改为:
int minCapacity = off + values.length * 6 + 2;

### What this PR does / why we need it?



### Summary of your change



#### Please indicate you've done the following:

- [ ] Made sure tests are passing and test coverage is added if needed.
- [ ] Made sure commit message follow the rule of [Conventional Commits specification](https://www.conventionalcommits.org/).
- [ ] Considered the docs impact and opened a new docs issue or PR with docs changes if needed.



Patch:
diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java b/core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
index 1797b4586..8fa50d841 100644
--- a/core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
+++ b/core/src/main/java/com/alibaba/fastjson2/JSONWriterUTF8.java
@@ -878,7 +878,7 @@ class JSONWriterUTF8
     }
 
     protected final void writeStringEscaped(byte[] values) {
-        int minCapacity = off + values.length * 4 + 2;
+        int minCapacity = off + values.length * 6 + 2;
         if (minCapacity >= this.bytes.length) {
             ensureCapacity(minCapacity);
         }


Test patch:
diff --git a/core/src/test/java/com/alibaba/fastjson2/JSONWriterUTF8Test.java b/core/src/test/java/com/alibaba/fastjson2/JSONWriterUTF8Test.java
index 8c37f02a4..cda2c0150 100644
--- a/core/src/test/java/com/alibaba/fastjson2/JSONWriterUTF8Test.java
+++ b/core/src/test/java/com/alibaba/fastjson2/JSONWriterUTF8Test.java
@@ -1,5 +1,6 @@
 package com.alibaba.fastjson2;
 
+import com.alibaba.fastjson2.JSONWriter.Context;
 import com.alibaba.fastjson2.annotation.JSONField;
 import org.junit.jupiter.api.Test;
 
@@ -672,6 +673,20 @@ public class JSONWriterUTF8Test {
         assertEquals(str, parse);
     }
 
+    @Test
+    public void writeStringEscaped() {
+        byte[] bytes = new byte[1024 * 128];
+        Arrays.fill(bytes, (byte) 1);
+        Context context = JSONFactory.createWriteContext(JSONWriter.Feature.PrettyFormat);
+        try (JSONWriterUTF8 jsonWriter = new JSONWriterUTF8(context)) {
+            jsonWriter.writeStringEscaped(bytes);
+            String json = jsonWriter.toString();
+            String str = new String(bytes, 0, bytes.length, StandardCharsets.ISO_8859_1);
+            Object parse = JSON.parse(json);
+            assertEquals(str, parse);
+        }
+    }
+
     @Test
     public void writeName8() {
         JSONWriterUTF8 jsonWriter = new JSONWriterUTF8(JSONFactory.createWriteContext());
Repository: alibaba/fastjson2
Pull request #3238 (2025-01-01 02:58:07)

jsonpath support
### What this PR does / why we need it?



### Summary of your change



#### Please indicate you've done the following:

- [ ] Made sure tests are passing and test coverage is added if needed.
- [ ] Made sure commit message follow the rule of [Conventional Commits specification](https://www.conventionalcommits.org/).
- [ ] Considered the docs impact and opened a new docs issue or PR with docs changes if needed.



Patch:
diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONReader.java b/core/src/main/java/com/alibaba/fastjson2/JSONReader.java
index 35a1ec348..900ad14c9 100644
--- a/core/src/main/java/com/alibaba/fastjson2/JSONReader.java
+++ b/core/src/main/java/com/alibaba/fastjson2/JSONReader.java
@@ -487,6 +487,7 @@ public abstract class JSONReader
             case ')':
             case '_':
             case ',':
+            case '~':
                 return (char) c;
             default:
                 throw new JSONException(info("unclosed.str '\\" + (char) c));


Test patch:
diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3219.java b/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3219.java
new file mode 100644
index 000000000..830e3bfa7
--- /dev/null
+++ b/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3219.java
@@ -0,0 +1,27 @@
+package com.alibaba.fastjson2.issues_3200;
+
+import com.alibaba.fastjson2.JSON;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static com.alibaba.fastjson2.JSONWriter.Feature.ReferenceDetection;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+public class Issue3219 {
+    @Test
+    public void test() {
+        Map<String, Object> innerMap = new HashMap<>();
+        innerMap.put("xxx", "xxxx");
+        innerMap.put("ttt", "tttt");
+        Map<String, Object> map = new LinkedHashMap<>();
+        map.put("key1~", innerMap);
+        map.put("key2", innerMap);
+
+        String josnStr1 = JSON.toJSONString(map, ReferenceDetection);
+        Map map2 = JSON.parseObject(josnStr1, Map.class);
+        assertSame(map2.get("key2"), map2.get("key1~"));
+    }
+}
Repository: alibaba/fastjson2
Pull request #3240 (2025-01-01 04:15:40)

support parse binary
### What this PR does / why we need it?



### Summary of your change



#### Please indicate you've done the following:

- [ ] Made sure tests are passing and test coverage is added if needed.
- [ ] Made sure commit message follow the rule of [Conventional Commits specification](https://www.conventionalcommits.org/).
- [ ] Considered the docs impact and opened a new docs issue or PR with docs changes if needed.



Patch:
diff --git a/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderImplObject.java b/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderImplObject.java
index 829f37a06..085070893 100644
--- a/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderImplObject.java
+++ b/core/src/main/java/com/alibaba/fastjson2/reader/ObjectReaderImplObject.java
@@ -289,6 +289,9 @@ public final class ObjectReaderImplObject
             case 'n':
                 value = jsonReader.readNullOrNewDate();
                 break;
+            case 'x':
+                value = jsonReader.readBinary();
+                break;
             case 'S':
                 if (jsonReader.nextIfSet()) {
                     HashSet<Object> set = new HashSet<>();


Test patch:
diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3208.java b/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3208.java
index 4d6ad314c..812e9eda0 100644
--- a/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3208.java
+++ b/core/src/test/java/com/alibaba/fastjson2/issues_3200/Issue3208.java
@@ -9,6 +9,8 @@ import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
 public class Issue3208 {
     @Test
     public void testArray() {
@@ -24,4 +26,15 @@ public class Issue3208 {
         Object parsed = JSON.parse(new String(jsonBytes));
         Assertions.assertNotNull(parsed);
     }
+
+    @Test
+    public void test() {
+        byte[] data = new byte[3];
+        data[0] = 1;
+        data[1] = 2;
+        data[2] = 3;
+        // 老版本会将数据转成jsonString并放到redis里面
+        String jsonString = com.alibaba.fastjson.JSONObject.toJSONString(data, SerializerFeature.WriteClassName, SerializerFeature.NotWriteDefaultValue);
+        assertEquals("[1, 2, 3]", Arrays.toString((byte[]) com.alibaba.fastjson2.JSON.parse(jsonString)));
+    }
 }