diff --git a/lib/oxrdf/src/parser.rs b/lib/oxrdf/src/parser.rs index 26c7459e..af74b151 100644 --- a/lib/oxrdf/src/parser.rs +++ b/lib/oxrdf/src/parser.rs @@ -175,7 +175,7 @@ fn read_blank_node(s: &str) -> Result<(BlankNode, &str), TermParseError> { fn read_literal(s: &str) -> Result<(Literal, &str), TermParseError> { let s = s.trim(); 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(); while let Some(c) = chars.next() { match c { diff --git a/lib/sparesults/src/csv.rs b/lib/sparesults/src/csv.rs index 8a317801..9db6e1f2 100644 --- a/lib/sparesults/src/csv.rs +++ b/lib/sparesults/src/csv.rs @@ -252,6 +252,7 @@ impl TsvSolutionsReader { mod tests { use super::*; use crate::QuerySolution; + use std::io::Cursor; use std::rc::Rc; use std::str; @@ -323,4 +324,19 @@ mod tests { assert_eq!(str::from_utf8(&result).unwrap(), "?x\t?literal\n\t\"String\"\n\t\"String-with-dquote\\\"\"\n_:b0\t\"Blank node\"\n\t\"Missing 'x'\"\n\t\n\t\n_:b1\t\"String-with-lang\"@en\n_:b1\t123"); 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(()) + } }