strong-xml icon indicating copy to clipboard operation
strong-xml copied to clipboard

Syntax Error on Self-Closing Element of type `Option<String>`

Open kevincox opened this issue 3 years ago • 1 comments
trafficstars

I'm not sure if this is "intended" as it is definitely a weird case. But see the following example:

#[derive(strong_xml::XmlRead)]
#[xml(tag = "head")]
pub struct Head {
	#[xml(flatten_text="title")]
	pub title: Option<String>,
}

fn main() {
	let _: Head = strong_xml::XmlRead::from_str(r#"
		<head>
			<title/>
		</head>
	"#).unwrap();
}

(Example inspired by https://github.com/Holllo/opml/blob/75eb03b23fa12cd241883d9ee86f16e93d274ff0/opml_api/source/lib.rs#L238)

Running this results in:

thread 'main' panicked at 'called Result::unwrap() on an Err value: UnexpectedToken { token: "ElementEnd { end: Empty, span: StrSpan("/>" 19..21) }" }', src/main.rs:13:9

I would expect that this resulted in an empty string.

This seems to be backed by my reading of the xml spec.

[Definition: An element with no content is said to be empty.] The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. [Definition: An empty-element tag takes a special form:]

It seems that <foo></foo> and <foo/> are intended to be equivalent. I'm not 100% sure if if "no content" is equivalent to "content of an empty string" but they appear to be as far as I have read. So I think that this should parse just like <title></title> does.

kevincox avatar May 03 '22 22:05 kevincox

@PoiScript do you have any guidance on to how to move this forward?

kevincox avatar May 16 '22 17:05 kevincox