Skip to content

Commit 44a9110

Browse files
committed
Only check attributes of current tag for duplicates.
1 parent 9089fc7 commit 44a9110

File tree

1 file changed

+16
-10
lines changed
  • xml5ever/src/tree_builder

1 file changed

+16
-10
lines changed

xml5ever/src/tree_builder/mod.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ pub struct XmlTreeBuilder<Handle, Sink> {
196196
/// Current namespace identifier
197197
current_namespace: NamespaceMap,
198198

199-
/// List of already present namespace local name attribute pairs.
200-
present_attrs: HashSet<(Namespace, LocalName)>,
201-
202199
/// Current tree builder phase.
203200
phase: XmlPhase,
204201
}
@@ -221,7 +218,6 @@ where
221218
curr_elem: None,
222219
namespace_stack: NamespaceMapStack::new(),
223220
current_namespace: NamespaceMap::empty(),
224-
present_attrs: HashSet::new(),
225221
phase: Start,
226222
}
227223
}
@@ -307,28 +303,38 @@ where
307303
// existing namespace context.
308304
//
309305
// Returns false if the attribute is a duplicate, returns true otherwise.
310-
fn bind_attr_qname(&mut self, name: &mut QualName) -> bool {
306+
fn bind_attr_qname(
307+
&mut self,
308+
present_attrs: &mut HashSet<(Namespace, LocalName)>,
309+
name: &mut QualName,
310+
) -> bool {
311311
// Attributes don't have default namespace
312312
let mut not_duplicate = true;
313313

314314
if name.prefix.is_some() {
315315
self.bind_qname(name);
316-
not_duplicate = self.check_duplicate_attr(name);
316+
not_duplicate = Self::check_duplicate_attr(present_attrs, name);
317317
}
318318
not_duplicate
319319
}
320320

321-
fn check_duplicate_attr(&mut self, name: &QualName) -> bool {
321+
fn check_duplicate_attr(
322+
present_attrs: &mut HashSet<(Namespace, LocalName)>,
323+
name: &QualName,
324+
) -> bool {
322325
let pair = (name.ns.clone(), name.local.clone());
323326

324-
if self.present_attrs.contains(&pair) {
327+
if present_attrs.contains(&pair) {
325328
return false;
326329
}
327-
self.present_attrs.insert(pair);
330+
present_attrs.insert(pair);
328331
true
329332
}
330333

331334
fn process_namespaces(&mut self, tag: &mut Tag) {
335+
// List of already present namespace local name attribute pairs.
336+
let mut present_attrs: HashSet<(Namespace, LocalName)> = Default::default();
337+
332338
let mut new_attr = vec![];
333339
// First we extract all namespace declarations
334340
for attr in tag.attrs.iter_mut().filter(|attr| {
@@ -343,7 +349,7 @@ where
343349
attr.name.prefix != Some(namespace_prefix!("xmlns"))
344350
&& attr.name.local != local_name!("xmlns")
345351
}) {
346-
if self.bind_attr_qname(&mut attr.name) {
352+
if self.bind_attr_qname(&mut present_attrs, &mut attr.name) {
347353
new_attr.push(attr.clone());
348354
}
349355
}

0 commit comments

Comments
 (0)