Skip to content

Commit

Permalink
Simplify checks
Browse files Browse the repository at this point in the history
That way they are more easily to understand
  • Loading branch information
Mingun committed Sep 3, 2023
1 parent 218dfe3 commit 220c269
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,20 @@ impl NamespaceResolver {
level,
});
}
Some(PrefixDeclaration::Named(prefix))
if prefix == RESERVED_NAMESPACE_XMLNS.0.into_inner() =>
{
Some(PrefixDeclaration::Named(b"xml")) => {
if Namespace(&v) != RESERVED_NAMESPACE_XML.1 {
// error, `xml` prefix explicitly set to different value
return Err(Error::ReservedNamespaceError {
prefix: "xml".to_string(),
name: String::from_utf8(v.to_vec()).unwrap(),
});
}
// don't add another NamespaceEntry for the `xml` namespace prefix
}
Some(PrefixDeclaration::Named(b"xmlns")) => {
// error, `xmlns` prefix explicitly set
return Err(Error::ReservedNamespaceError {
prefix: String::from_utf8(prefix.to_vec()).unwrap(),
prefix: "xmlns".to_string(),
name: String::from_utf8(v.to_vec()).unwrap(),
});
}
Expand All @@ -493,30 +501,21 @@ impl NamespaceResolver {
name: String::from_utf8(v.to_vec()).unwrap(),
});
} else if v == RESERVED_NAMESPACE_XML.1.into_inner() {
if prefix != RESERVED_NAMESPACE_XML.0.into_inner() {
// error, non-`xml` prefix set to xml uri
return Err(Error::ReservedNamespaceError {
prefix: String::from_utf8(prefix.to_vec()).unwrap(),
name: String::from_utf8(v.to_vec()).unwrap(),
});
}
// don't add another NamespaceEntry for the `xml` namespace prefix
} else if prefix == RESERVED_NAMESPACE_XML.0.into_inner() {
// xml namespace name must not be correct
// error, non-`xml` prefix set to xml uri
return Err(Error::ReservedNamespaceError {
prefix: String::from_utf8(prefix.to_vec()).unwrap(),
name: String::from_utf8(v.to_vec()).unwrap(),
});
} else {
buffer.extend_from_slice(prefix);
buffer.extend_from_slice(&v);
self.bindings.push(NamespaceEntry {
start,
prefix_len: prefix.len(),
value_len: v.len(),
level,
});
}

buffer.extend_from_slice(prefix);
buffer.extend_from_slice(&v);
self.bindings.push(NamespaceEntry {
start,
prefix_len: prefix.len(),
value_len: v.len(),
level,
});
}
None => {}
}
Expand Down

0 comments on commit 220c269

Please sign in to comment.