Fix bug 666222

This also adds some smaller, isolated tests related to bug 66622.