I came across this when looking into this issue:
I’ve made a PR which fixes it:
https://github.com/discourse/discourse/pull/29853