osipovartem commented on code in PR #11409:
URL: https://github.com/apache/arrow-rs/pull/11409#discussion_r4702485507


##########
parquet-variant-json/src/from_json.rs:
##########
@@ -667,4 +1043,136 @@ mod test {
         }
         .run()
     }
+
+    #[test]
+    fn test_json_to_variant_escaped_strings() -> Result<(), ArrowError> {
+        let json = r#"{"line\nkey":"quote: \"; slash: \\; unicode: \u2764"}"#;
+        let mut variant_builder = VariantBuilder::new();
+        variant_builder.append_json(json)?;
+        let (metadata, value) = variant_builder.finish();
+        let variant = Variant::try_new(&metadata, &value)?;
+        assert_eq!(
+            variant.to_json_string()?,
+            "{\"line\\nkey\":\"quote: \\\"; slash: \\\\; unicode: ❤\"}"
+        );
+        Ok(())
+    }
+
+    #[test]
+    fn test_json_to_variant_rejects_invalid_json() {
+        let invalid = [
+            "",
+            "nul",
+            "True",
+            "[",
+            "{",
+            "[1,]",
+            "[1 2]",
+            "[1,,2]",
+            "{\"a\":1,}",
+            "{\"a\" 1}",
+            "{\"a\":1 \"b\":2}",
+            concat!("{", "a:1}"),
+            "01",
+            "-01",
+            "+1",
+            ".1",
+            "1.",
+            "1e",
+            "1e+",
+            "true false",
+            "\"unterminated",
+            "\"bad\\xescape\"",
+            "\"bad\\u12x4\"",
+            "\"lone high surrogate: \\ud800\"",
+            "\"lone low surrogate: \\udc00\"",
+        ];
+
+        for json in invalid {
+            let mut builder = VariantBuilder::new();
+            assert!(builder.append_json(json).is_err(), "accepted {json:?}");
+        }
+    }
+
+    #[test]
+    fn test_json_to_variant_rejects_non_finite_double() {
+        let mut builder = VariantBuilder::new();
+        let error = builder.append_json("1e400").unwrap_err().to_string();
+        assert!(error.contains("finite number"), "{error}");
+    }
+

Review Comment:
   Agreed. `1e400` now has its own row in the invalid-input table, which checks 
both rejection and builder rollback.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to