$ setopt sh_word_split
$ mkdir 'foo bar'
$ cd 'foo bar'
$ ls
_per-directory-history-addhistory:11: failed to write history file /Users/xxx/.local/share/directory_history/Users/me/tmp/foo: is a directory
_per-directory-history-change-directory:9: failed to write history file /Users/xxx/.local/share/directory_history/Users/me/tmp/foo: is a directory
I think we need to quote variables properly.