So, zsh has the KEYBOARD_HACK option as an anti-annoyance feature, which removes a trailing quote character in case you accidentally hit it along with enter. However, this naively looks at whether there is an odd number of quotes at the command line, which causes it to invert when you have (and odd number of) escaped quotes, removing the trailing quote when it shouldn't and vice versa. For example, if you write 'test'\''test' or 'test'"'"'test'' with this enabled, zsh will inapropriately remove the trailing quotes, whereas if you write echo 'test'\''test'' it will not remove the trailing quote. Instead, zsh needs to more smartly check whether the quoting is unbalanced and if removing the trailing quote would make it balanced.