Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kevincox opened this issue May 3, 2022 · 1 comment · May be fixed by #36
Open

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

kevincox opened this issue May 3, 2022 · 1 comment · May be fixed by #36

Comments

@kevincox
Copy link

kevincox commented May 3, 2022

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 added a commit to kevincox/strong-xml that referenced this issue May 3, 2022
@kevincox
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant