What kind of worms? Most kinds are very minor and are quickly removed with medication.
It is very easy for them to get it if you take them to high dog traffic areas such as parks. All they would have to do is run through some poop then lick their paw ... so it might not have been so obvious as if they sniffed poop.
Don't worry about it. You can get rid of the worms quickly.
Bookmarks