Skip to content

Lifetime on Attributes is wrong #332

Open

Description

@stevenroose

So Attributes has a generic parameter 'a, but it doesn't correspond to the same lifetime of the slice inside the reader. It corresponds to the lifetime of the borrow of the reader itself when the Attributes object was created.

One can easily see that making this change will break the code:

diff --git a/src/events/mod.rs b/src/events/mod.rs
index 5e598bd..861ce7b 100644
--- a/src/events/mod.rs
+++ b/src/events/mod.rs
@@ -223,12 +223,12 @@ impl<'a> BytesStart<'a> {
     }
 
     /// Returns an iterator over the attributes of this tag.
-    pub fn attributes(&self) -> Attributes {
+    pub fn attributes(&self) -> Attributes<'a> {
         Attributes::new(&self.buf, self.name_len)
     }
 
     /// Returns an iterator over the HTML-like attributes of this tag (no mandatory quotes or `=`).
-    pub fn html_attributes(&self) -> Attributes {
+    pub fn html_attributes(&self) -> Attributes<'a> {
         Attributes::html(self, self.name_len)
     }
 

I'm working on fixing that using as little as possible reallocations, which would mean having a double lifetime on Attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions