builder: Fix handling of ENV references that reference themselves, plus tests.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)