Fix various crashes with pluginpref
Fixed expand_homedir to handle paths like "~user" correctly.