I don't really like the assumptions made in the patch.
Wouldn't it be better to use PageRoot? We know that page root always points to [your install directory]/www. All you need to do is count the number of directories in the [your install directory] path and only look for www and admin-www in the trailing part of the path being tested - instead of your hard-wired "3" approach.
If you want to take a shot at that, I'd say do it, test it, and go ahead and commit it ...
And TIA!