Sorry I didn't get around to looking at this before you wrote a patch,
but I think you're overthinking this.
I confirm that your patch seems to work, thanks very much. Adding some tests is particularly helpful: if I'd done that, I wouldn't have gotten in this mess in the first place!
How can one overthink a logical problem? It's possible to underthink, but in this case, I believe I misunderstood what the whitespace-empty-at-eob-regexp was supposed to match: only empty lines, not trailing space at the end of non-empty lines (as one of your comments mentions). (I was trying to make it match ALL the whitespace at the end of the buffer, as you probably realised.)
The only thing I'd change in your match is, as in mine, remove the FIXME after save-match-data.