-
Notifications
You must be signed in to change notification settings - Fork 21
fix; unescape xml attribute value. #218
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
base: master
Are you sure you want to change the base?
Conversation
Bergmann89
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Postur, Thanks for the fix. May you also add a simple unit test for this instead of using the example?
|
sorry I missed the tests, this fix requires more than I first thought.
If we unescape in the let value = unescape(from_utf8(value)?)?;
let value = T::deserialize_bytes(self, value.as_bytes())?;but converting, unecsaping, then converting again feels dirty. |
|
You can use Had a short test on my side, and this works as intended: /// Helper function to convert and store an attribute from the XML event.
///
/// Since attributes needs to be escaped this will convert the passed
/// `value` bytes to a UTF-8 string, unescape it and then deserialize
/// it using the [`DeserializeBytes::deserialize_str`] method.
///
/// # Errors
///
/// Returns an [`struct@Error`] with [`ErrorKind::DuplicateAttribute`] if `store`
/// already contained a value.
pub fn read_attrib<T>(
&mut self,
store: &mut Option<T>,
name: &'static [u8],
value: &[u8],
) -> Result<(), Error>
where
T: DeserializeBytes,
{
if store.is_some() {
Err(ErrorKind::DuplicateAttribute(RawByteStr::from(name)))?;
}
let value = from_utf8(value)?;
let value = unescape(value)?;
let value = T::deserialize_str(self, &value)?;
*store = Some(value);
Ok(())
}I also updated the doc string to make it clear to the user, so you can use this as drop-in replacement for the PR. |
issue:
if an attribute value contains escaped chars, it is not unescaped when using the quick_xml deserializer.
reproduce:
>to the end of "foo"note: the
&got serialized to&correctly.what we expected:

fix:
when deserializing the
Stringtype withString::deserialize_bytes()from thepub fn read_attrib<T>functionwe want to receive it unescaped back.
file: xsd-parser-types/src/quick_xml/deserialize.rs