This, unfortunately, has a side-effect where if an IRI at this point ends in a language code (e.g. ".es"), it will also be stripped. However, I do not believe this is a common occurrence and cannot find evidence that it is. The only workaround which comes to mind is testing whether the extension is in the ISO 3166-1 list.