pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
228 stars 24 forks source link

empty string seems to confuse sophia (0.8.0-alpha) #127

Closed SimonBin closed 1 year ago

SimonBin commented 1 year ago
<urn:x:s> <urn:x:p> "" .
nt::parse_bufread(reader).collect_triples().unwrap()
stacktrace ``` panicked at 'index out of bounds: the len is 0 but the index is 0', cargo/git/checkouts/mownstr-b4cf7b39965722e5/c88467d/src/lib.rs:146:35 stack backtrace: 0: rust_begin_unwind at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:575:5 1: core::panicking::panic_fmt at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/panicking.rs:64:14 2: core::panicking::panic_bounds_check at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/panicking.rs:148:5 3: >>::from at cargo/git/checkouts/mownstr-b4cf7b39965722e5/c88467d/src/lib.rs:146:35 4: >::into at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/convert/mod.rs:726:9 5: >::from at cargo/git/checkouts/mownstr-b4cf7b39965722e5/c88467d/src/lib.rs:158:9 6: >::into at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/convert/mod.rs:726:9 7: sophia_api::term::_simple::ensure_owned at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/api/src/term/_simple.rs:107:9 8: ::from_term at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/api/src/term/_simple.rs:119:27 9: as sophia_inmem::index::TermIndex>::ensure_index at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/inmem/src/index.rs:115:17 10: as sophia_api::graph::MutableGraph>::insert at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/inmem/src/graph.rs:108:18 11: sophia_api::graph::MutableGraph::insert_triple at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/api/src/graph.rs:359:9 12: as sophia_api::graph::CollectibleGraph>::from_triple_source::{{closure}} at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/inmem/src/graph.rs:139:41 13: core::ops::function::impls:: for &mut F>::call_mut at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/ops/function.rs:298:13 14: as sophia_api::source::_triple::TripleSource>::try_for_some_triple::{{closure}} at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/rio/src/parser.rs:40:17 15: as rio_api::parser::TriplesParser>::parse_step at cargo/registry/src/github.com-1ecc6299db9ec823/rio_turtle-0.8.0/src/ntriples.rs:66:31 16: as sophia_api::source::_triple::TripleSource>::try_for_some_triple at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/rio/src/parser.rs:38:9 17: sophia_api::source::_triple::TripleSource::try_for_each_triple at cargo/git/checkouts/sophia_rs-ca1fdaaafda2a8dd/a393ab3/api/src/source/_triple.rs:41:15 ```
pchampin commented 1 year ago

Thanks for reporting this.

However, I can't reproduce this bug with the latest version of the code. Could you update your repo (or use the brand new "0.8.0-alpha.0" on crates.io) and test again?

SimonBin commented 1 year ago

still happens:

test.nt

<urn:x:s> <urn:x:p> "" .
[dependencies]
sophia = { version = "0.8.0-alpha.0" }
fn main() {
    let reader = BufReader::new(File::open("test.nt").unwrap());
    let graph: LightGraph = nt::parse_bufread(reader).collect_triples().unwrap();
    let mut nt_stringifier = NtSerializer::new_stringifier();
    let ser = nt_stringifier.serialize_graph(&graph).unwrap().as_str();
    println!("{}", ser);
}

the problem seems to be here: https://github.com/pchampin/mownstr/blob/v0.2.0/src/lib.rs#L146

        let addr = NonNull::from(&other.as_bytes()[0]);
pchampin commented 1 year ago

It was indeed a stupid bug in mownstr causing this problem. It was fixed in mownstr 0.2.1, and I upgraded the dependency in sophia. Thanks for spotting it.

At the moment, you can fix your issue by using the following dependency:

sophia = { version = "0.8.0-alpha.0", git = "https://github.com/pchampin/sophia_rs" }

Shortly, I will release a new version of sophia on crates.io that will integrate this change. But I'm reluctant to publish a new release for such a small change -- unless it is blocking for you. Just let me know.

SimonBin commented 1 year ago

no worries glad you could reproduce the issue