Skip to content

Commit

Permalink
fixed null stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mburridge96 committed Nov 6, 2024
1 parent 8babe6e commit 439e4a4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn add_dynamic_entity() -> Option<HashMap<String, DynamicEntity>> {
let bvalue = parse_bool(value);
match bvalue {
Ok(value) => {
dynamic_entity.insert(key, DynamicEntity::EntityBool(value));
dynamic_entity.insert(key, DynamicEntity::EntityBool(Some(value)));
}
Err(e) => println!("An error occurred: {}", e),
}
Expand Down
4 changes: 2 additions & 2 deletions python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added python/example/example.zip
Binary file not shown.
9 changes: 7 additions & 2 deletions python/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ pub fn convert_dynamic_entity_to_pyobject(py: Python, value: &DynamicEntity) ->
);
py_list.into()
}
DynamicEntity::EntityBool(b) => PyBool::new_bound(py, *b).into_py(py),
DynamicEntity::EntityBool(b) => {
match b {
Some(value) => PyBool::new_bound(py, *value).into_py(py), // If it's a bool, convert it
None => py.None().into_py(py), // If it's None, keep it as None in Python
}
}
DynamicEntity::Entityi64(num) => (*num).into_py(py),
DynamicEntity::Entityf64(num) => PyFloat::new_bound(py, *num).into(),
DynamicEntity::EntityVeci64(vec) => {
Expand Down Expand Up @@ -595,7 +600,7 @@ fn convert_pyobject_to_dynamic_entity(py: Python, obj: &PyAny) -> PyResult<Dynam
}
// Boolean
if let Ok(b) = obj.extract::<bool>() {
return Ok(DynamicEntity::EntityBool(b));
return Ok(DynamicEntity::EntityBool(Some(b)));
}
// i64
if let Ok(i) = obj.extract::<i64>() {
Expand Down
12 changes: 6 additions & 6 deletions src/ro_crate/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ pub enum DynamicEntity {
EntityVecString(Vec<String>),
EntityId(Id),
EntityIdVec(Vec<Id>),
EntityBool(bool),
Entityi64(i64),
Entityf64(f64),
EntityVeci64(Vec<i64>),
EntityVecf64(Vec<f64>),
EntityBool(Option<bool>),
EntityVec(Vec<DynamicEntity>),
EntityObject(HashMap<String, DynamicEntity>),
EntityVecObject(Vec<HashMap<String, DynamicEntity>>),
Expand Down Expand Up @@ -157,9 +157,9 @@ mod tests {

#[test]
fn test_dynamic_entity_bool() {
let entity = DynamicEntity::EntityBool(true);
let entity = DynamicEntity::EntityBool(Some(true));
match entity {
DynamicEntity::EntityBool(value) => assert!(value),
DynamicEntity::EntityBool(Some(value)) => assert!(value),
_ => panic!("EntityBool variant expected"),
}
}
Expand Down Expand Up @@ -197,10 +197,10 @@ mod tests {
#[test]
fn test_dynamic_entity_fallback_empty() {
let json_value = json!({});
let entity = DynamicEntity::Fallback(json_value.clone());
let entity = DynamicEntity::Fallback(Some(json_value.clone()));
match entity {
DynamicEntity::Fallback(value) => assert_eq!(value, json_value),
_ => panic!("Fallback variant expected"),
DynamicEntity::Fallback(Some(value)) => assert_eq!(value, json_value),
_ => panic!("Fallback variant with expected value was not found"),
}
}

Expand Down
5 changes: 3 additions & 2 deletions tests/fixtures/_ro-crate-metadata-minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"@type": "CreativeWork",
"description": "This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Australia License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/au/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.",
"identifier": "https://creativecommons.org/licenses/by-nc-sa/3.0/au/",
"name": "Attribution-NonCommercial-ShareAlike 3.0 Australia (CC BY-NC-SA 3.0 AU)"
"name": "Attribution-NonCommercial-ShareAlike 3.0 Australia (CC BY-NC-SA 3.0 AU)",
"value": null
}
]
}
}

0 comments on commit 439e4a4

Please sign in to comment.