Fix some special cases

https://github.com/rails/rails/commit/94e8fc06199d385174ff4d66a0be4d23e2d45f2f
and
https://github.com/rails/rails/commit/e428ddececf43923dec4299c40b29451e5bea80d