Fix handling of internal borders (Bug#16348).