Unintended functionality when creating links to sections with spaces

Steps to reproduce

Create link to section with spaces below current line

lorem ipsum [foo](#lorem-ipsum)
# Lorem Ipsum

Did you follow the troubleshooting guide? [Y/N]

Y

Expected result

Clicking on the [foo] link should redirect us to the header # Lorem Ipsum

Actual result

Broken Link


Additional information

Very much worth noting that this only breaks when spaces are involved, i.e.

lorem ipsum [foo](#lorem)
# Lorem

Works as intended