For extensions, chop off all characters at the first char that is not alphanumeric (or underscore). The situation does happen, e.g. for files named from URIs.