Check whether `$canonical` is a string before treating it as one.