Add tests for bugs [336441ed59] and [581937ab1e] from core-8-5-branch.