Improved the depth calculation in sanitize_path() so that it properly