Skip to content

Commit 63ef7c7

Browse files
authored
fix(format): Correctly deserialize json5 (#690)
Fixes #689
2 parents 35bafb9 + ea823c1 commit 63ef7c7

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

src/file/format/json5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'de> serde::de::Deserialize<'de> for Val {
2525
.i64(|value| Ok(Self::Integer(value)))
2626
.f64(|value| Ok(Self::Float(value)))
2727
.string(|value| Ok(Val::String(value.to_owned())))
28-
.none(|| Ok(Self::Null))
28+
.unit(|| Ok(Self::Null))
2929
.seq(|value| value.deserialize().map(Val::Array))
3030
.map(|value| value.deserialize().map(Val::Object))
3131
.deserialize(d)

tests/testsuite/file_json.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn test_file() {
1616
place: Place,
1717
#[serde(rename = "arr")]
1818
elements: Vec<String>,
19+
nullable: Option<String>,
1920
}
2021

2122
#[derive(Debug, Deserialize)]
@@ -52,7 +53,8 @@ fn test_file() {
5253
}
5354
},
5455
"FOO": "FOO should be overridden",
55-
"bar": "I am bar"
56+
"bar": "I am bar",
57+
"nullable": null
5658
}
5759
"#,
5860
FileFormat::Json,
@@ -92,6 +94,7 @@ fn test_file() {
9294
"John Smith".to_owned()
9395
);
9496
}
97+
assert_eq!(s.nullable, None);
9598
}
9699

97100
#[test]

tests/testsuite/file_json5.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn test_file() {
1616
place: Place,
1717
#[serde(rename = "arr")]
1818
elements: Vec<String>,
19+
nullable: Option<String>,
1920
}
2021

2122
#[derive(Debug, Deserialize)]
@@ -54,6 +55,7 @@ fn test_file() {
5455
},
5556
FOO: "FOO should be overridden",
5657
bar: "I am bar",
58+
nullable: null
5759
}
5860
"#,
5961
FileFormat::Json5,
@@ -93,6 +95,7 @@ fn test_file() {
9395
"John Smith".to_owned()
9496
);
9597
}
98+
assert_eq!(s.nullable, None);
9699
}
97100

98101
#[test]

tests/testsuite/file_ron.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ fn test_file() {
1616
place: Place,
1717
#[serde(rename = "arr")]
1818
elements: Vec<String>,
19+
nullable: Option<String>,
1920
}
2021

2122
#[derive(Debug, Deserialize)]
@@ -54,7 +55,8 @@ fn test_file() {
5455
}
5556
),
5657
FOO: "FOO should be overridden",
57-
bar: "I am bar"
58+
bar: "I am bar",
59+
nullable: None
5860
)
5961
"#,
6062
FileFormat::Ron,
@@ -95,6 +97,7 @@ fn test_file() {
9597
"John Smith".to_owned()
9698
);
9799
}
100+
assert_eq!(s.nullable, None);
98101
}
99102

100103
#[test]

tests/testsuite/file_yaml.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn test_file() {
1818
place: Place,
1919
#[serde(rename = "arr")]
2020
elements: Vec<String>,
21+
nullable: Option<String>,
2122
}
2223

2324
#[derive(Debug, Deserialize)]
@@ -52,6 +53,7 @@ place:
5253
# For override tests
5354
FOO: FOO should be overridden
5455
bar: I am bar
56+
nullable: null
5557
"#,
5658
FileFormat::Yaml,
5759
))
@@ -90,6 +92,7 @@ bar: I am bar
9092
"John Smith".to_owned()
9193
);
9294
}
95+
assert_eq!(s.nullable, None);
9396
}
9497

9598
#[test]

0 commit comments

Comments
 (0)