Fixes Literal N-Triples parsing bug

It was crashing when the input were only a double quote
pull/190/head
Tpt 3 years ago
parent d4d7f2dc49
commit 0105a4a54a
  1. 2
      lib/oxrdf/src/parser.rs
  2. 16
      lib/sparesults/src/csv.rs

@ -175,7 +175,7 @@ fn read_blank_node(s: &str) -> Result<(BlankNode, &str), TermParseError> {
fn read_literal(s: &str) -> Result<(Literal, &str), TermParseError> { fn read_literal(s: &str) -> Result<(Literal, &str), TermParseError> {
let s = s.trim(); let s = s.trim();
if let Some(s) = s.strip_prefix('"') { if let Some(s) = s.strip_prefix('"') {
let mut value = String::with_capacity(s.len() - 1); let mut value = String::with_capacity(s.len());
let mut chars = s.chars(); let mut chars = s.chars();
while let Some(c) = chars.next() { while let Some(c) = chars.next() {
match c { match c {

@ -252,6 +252,7 @@ impl<R: BufRead> TsvSolutionsReader<R> {
mod tests { mod tests {
use super::*; use super::*;
use crate::QuerySolution; use crate::QuerySolution;
use std::io::Cursor;
use std::rc::Rc; use std::rc::Rc;
use std::str; use std::str;
@ -323,4 +324,19 @@ mod tests {
assert_eq!(str::from_utf8(&result).unwrap(), "?x\t?literal\n<http://example/x>\t\"String\"\n<http://example/x>\t\"String-with-dquote\\\"\"\n_:b0\t\"Blank node\"\n\t\"Missing 'x'\"\n\t\n<http://example/x>\t\n_:b1\t\"String-with-lang\"@en\n_:b1\t123"); assert_eq!(str::from_utf8(&result).unwrap(), "?x\t?literal\n<http://example/x>\t\"String\"\n<http://example/x>\t\"String-with-dquote\\\"\"\n_:b0\t\"Blank node\"\n\t\"Missing 'x'\"\n\t\n<http://example/x>\t\n_:b1\t\"String-with-lang\"@en\n_:b1\t123");
Ok(()) Ok(())
} }
#[test]
fn test_bad_tsv() -> io::Result<()> {
let bad_tsvs = vec![
"?", "?p", "?p?o", "?p\n<", "?p\n_", "?p\n_:", "?p\n\"", "?p\n<<",
];
for bad_tsv in bad_tsvs {
if let TsvQueryResultsReader::Solutions { mut solutions, .. } =
TsvQueryResultsReader::read(Cursor::new(bad_tsv))?
{
while solutions.read_next()?.is_some() {}
}
}
Ok(())
}
} }

Loading…
Cancel
Save