NEXUS-5472: Garbage input for prefix UT

Added UT covering various "garbage" inputs.
Also, simplified how input detection is done.