Skip to content

Cloning an element with attributes creates an empty userData attribute #2356

Closed
anonyein/jsoup
#1

Description

@leomayer

We have in our tests the following element

<span id="test"></span>

In our code base we check if an element has no attribute except id. This is checked by the following code

e.clone()
	.removeAttr("id")
	.attributes()
	.isEmpty()

With 1.20.1 this return true while 1.21.1 this returns false. Somehow there is still a single attribute left. I would guess it has to do with the clone but I'm not sure.

I just report it but I'm aware that there is better method for checking, e.g.

e.attributes().size()==1 & e.attributes.hasKey("id")

Activity

  1. added
    bug
    on Jul 2, 2025
  2. changed the title [-]Regression 1.20.1 to 1.21.1: attributes fail[/-] [+]Cloning an element with attributes creates an empty userData attribute[/+] on Jul 2, 2025
  3. jhy commented on Jul 2, 2025

    @jhy
    Owner

    Thanks for the report; fixed!

    Caused by the changes for #2334.

  4. added this to the 1.21.2 milestone on Jul 2, 2025
  5. added a commit that references this issue on Jul 2, 2025
    fa61c69
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

    bug

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions