gazpacho icon indicating copy to clipboard operation
gazpacho copied to clipboard

attrs method output is changed when using find

Open cfrahnow opened this issue 5 years ago • 1 comments

find changes the content of attrs

When using the find method on a Soup object, the content of attrs is overwritten by the parameter attrs in find.

Steps to reproduce the issue

Try the following:

from gazpacho import Soup

div = Soup("<div id='my_id' />").find("div")
print(div.attrs)
div.find("span", {"id": "invalid_id"})
print(div.attrs)

The expected output will be the following, because we twice print the attributes of a:

{'id': 'my_id'}
{'id': 'my_id'}

But instead you actually receive:

{'id': 'my_id'}
{'id': 'invalid_id'}

which is wrong.

Environment:

  • OS: Linux
  • Version: 1.1

My current workaround is to save the attributes before I execute find.

cfrahnow avatar Mar 11 '21 23:03 cfrahnow

Good find! Hasn't ever been a problem for me in production, but should definitely be fixed. I've earmarked a week at the end of this quarter to clean up some outstanding issues.. I'll put this one in that work block!

maxhumber avatar Mar 12 '21 19:03 maxhumber