Salaam.
Salaam.
It is clear from 18:17, that the cave remained open.
It is clear in 18:18, that the dog was at the entrance, separate from its masters.
Or at least, it might not have had any occasion to answer the calls of nature.
It was not like our pets creating nuisance inside closed doors.
For, "....God loves those who turn to Him constantly, and He loves those who keep themselves pure and clean." (2:222)
Regards,
A. Ismail Sait.