pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
210 stars 23 forks source link

Panic when URI = prefix (empty suffix) #115

Closed KonradHoeffner closed 7 months ago

KonradHoeffner commented 1 year ago

Let's say I have a knowledge base under the namespace http://example.com/ and I use the URL equal to that namespace to denote meta information about the knowledge base, for example <http://example.com/> rdfs:label "this is an example knowledge base"@en..

However, using such a URI causes Sophia to panic:

Code

let iri = my_namespace.get("")?; // this works fine
mygraph.triples_with_s(&iri);  // this is line 131 that causes the panic shown below

Backtrace

thread 'actix-rt|system:0|arbiter:9' panicked at 'assertion failed: !sf.as_ref().is_empty()', /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_term-0.7.2/src/iri.rs:175:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1.62.1/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/1.62.1/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/1.62.1/library/core/src/panicking.rs:48:5
   3: sophia_term::iri::Iri<TD>::new_suffixed_unchecked
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_term-0.7.2/src/iri.rs:175:13
   4: <sophia_term::Term<&str> as core::convert::From<&T>>::from
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_term-0.7.2/src/lib.rs:552:33
   5: <sophia_inmem::graph::_hash_graph::HashGraph<I> as sophia_indexed::graph::IndexedGraph>::get_index
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_inmem-0.7.2/src/graph/_hash_graph.rs:83:31
   6: <sophia_inmem::graph::_spo_wrapper::SpoWrapper<T> as sophia_inmem::graph::_wrapper::GraphWrapper>::gw_triples_with_s
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_inmem-0.7.2/src/graph/_spo_wrapper.rs:60:27
   7: <sophia_inmem::graph::_spo_wrapper::SpoWrapper<T> as sophia_api::graph::_traits::Graph>::triples_with_s
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_inmem-0.7.2/src/graph/_wrapper.rs:214:13
   8: sophia_inmem::graph::_wrapper::GraphWrapper::gw_triples_with_s
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_inmem-0.7.2/src/graph/_wrapper.rs:40:9
   9: <sophia_inmem::graph::_ops_wrapper::OpsWrapper<T> as sophia_api::graph::_traits::Graph>::triples_with_s
             at /home/konrad/.cargo/registry/src/github.com-1ecc6299db9ec823/sophia_inmem-0.7.2/src/graph/_wrapper.rs:214:13
  10: rickview::rdf::connections
             at ./src/rdf.rs:131:5
pchampin commented 1 year ago

Thanks for reporting this. This is indeed a bug; Namespace::get produces an inconsistent SimpleIri when called with an empty str. Sorry about that. A workaround consists in replacing:

let iri = my_namespace.get("")?;

with

let iri = SimpleIri::new_unchecked(&my_namespace, None);

I'm in the middle of a big refactoring, in which this bug should be fixed.

pchampin commented 1 year ago

(FYI, I just edited the workaround, which was containing a typo)

pchampin commented 7 months ago

I'm in the middle of a big refactoring, in which this bug should be fixed.

this is indeed now fixed