Typically these are covered by your contract. If you work on something during work hours it definitely belongs to them, they paid you for it. If you write some code and then go home and write basically the exact same code then it still belongs to them: doesn't matter how you reproduced it, you're making a copy. If you work on something, and go home and apply what you learned that day to work on something similar but demonstrably unique it gets murky: your contract will usually have a "no-compete" clause in it saying that you aren't allowed to work on competing projects independently or for another company for a year. In the first two cases it's a legal matter of copyright, in the third it's a contract issue and the worst that'll happen is they sue you for contract violation.
In this case they aren't saying he took what he knew and created something unique, they are accusing him of literally taking the code, rewriting it, and claiming it as his own.
Like, you are hired to draw a picture for a company, the terms of which are that they fully own all rights to that picture. Before you turn it in, you take a photograph. After turning it in, you go home, and using that photograph make an almost identical copy. That's copyright infringement.
i expect to have ideas outside of work time that i want to open-source...
This has been brought up several times in court and successfully defended: as long as the idea is not directly related to the work you're hired to do it's trivial to the point that even a cheap lawyer can get you out of any potential trouble. Worst case, $100 for a well written letter saying "hahaha, no, go away" and you'll be fine.
And it's been my experience that most companies aren't complete assholes about it. The only time it gets problematic is when you try to make something outside of work hours that directly competes with what you do during work hours.