Repository navigation
Description
Description
The RDF/XML parser fails on a DOCTYPE entity declaration whose value is in single quotes:
<!ENTITY values should be enclosed in double quotes
XML 1.0 allows either quote character for entity values (production [9] EntityValue, https://www.w3.org/TR/xml/#NT-EntityValue):
EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
| "'" ([^%&'] | PEReference | Reference)* "'"
Single quotes are common in RDF/XML written by hand or by older tools. One example is the W3C OWL 2 test-case export, https://www.w3.org/2009/11/owl-test/approved/all.rdf, which declares <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>. The test ontologies embedded in it do the same.
To reproduce
Cargo.toml:
[package]
name = "repro"
version = "0.1.0"
edition = "2021"
[dependencies]
oxrdfxml = "=0.2.5"src/main.rs:
use oxrdfxml::RdfXmlParser;
fn parse(name: &str, quote: char) {
let input = format!(
r#"<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY ex {quote}http://example.com/{quote}>
]>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="&ex;s">
<rdf:value rdf:resource="&ex;o"/>
</rdf:Description>
</rdf:RDF>"#
);
let result: Result<Vec<_>, _> = RdfXmlParser::new().for_slice(&input).collect();
match result {
Ok(triples) => println!("{name}: ok, {} triple(s)", triples.len()),
Err(error) => println!("{name}: error: {error}"),
}
}
fn main() {
parse("double quotes", '"');
parse("single quotes", '\'');
}Expected: both inputs parse to the same triple, <http://example.com/s> rdf:value <http://example.com/o>.
Actual:
double quotes: ok, 1 triple(s)
single quotes: error: <!ENTITY values should be enclosed in double quotes
Environment
- oxrdfxml 0.2.5, the latest release. The same code is on
main(0.3.0-dev, commit506c6be). - rustc 1.97.0, Linux x86_64.
Cause
In parse_doctype (lib/oxrdfxml/src/parser.rs), the value is read with strip_prefix('"') and split_once('"'), so only a double quote is accepted. A possible fix is to accept either quote and close on the same one:
let quote = input.trim_start().chars().next().filter(|c| *c == '"' || *c == '\'').ok_or_else(|| {
RdfXmlSyntaxError::msg("<!ENTITY values should be enclosed in quotes")
})?;
let (entity_value, input) = input.trim_start()[1..].split_once(quote).ok_or_else(|| {
RdfXmlSyntaxError::msg("<!ENTITY declarations values should be enclosed in quotes")
})?;Workaround: rewrite the quotes in the DOCTYPE before parsing.
Activity
thelastbackspace commentedon Nov 5, 2026
Ran into this too. The DOCTYPE entity parsing in oxrdfxml only strips a leading
". I have a small fix that accepts either quote, plus a parser testsuite case. Opening a PR.oxrdfxml: accept single-quoted <!ENTITY> values (oxigraph#2023)