Moving a bit deeper into the realm of "how to break redirects..."
**Steps to replicate the issue**
* Ensure the page at [[Example]] exists (and is not a redirect).
* Create a redirect that points to `[[example#Foobar1234567890]]`
**What happens?**:
* `[[Example]]` exists (and is not a redirect). So, the criteria in {T326057} are met.
* The redirect half-works; it takes the user to page `[[Example]]`, but since there is no section heading `#Foobar1234567890`, it doesn't take the user to that section, but leaves the user at the top of the page.
**What should happen instead?**:
MediaWiki should check the heading exists on the target page. If it doesn't exist, an error should be thrown.
The error message should probably say something like:
> `The redirect's target page {{{1}}} exists, but does not have the heading {{{2}}}. Please check you have the right target page and that the heading exists on that page. If you resubmit the same target, the page will be created anyway.`
Ideally, this would also work for special pages, so `[[Special:Preferences#mw-prefsection-rendering]]` would be OK, but `[[Special:Preferences#I-like-bananas]]` wouldn't be.
**Benefits**:
Would prevent the creation of new "Broken section redirects," though it would still be possible if the name of a section heading is changed.
**Notes**:
A new function might have to be written to check whether section headings exist.
HTML `<a name="foo"/>` and `<a id="bar"/>` is not permitted by wikitext. Refer to https://www.mediawiki.org/wiki/Help:HTML_in_wikitext
However, custom content models are permitted, and these could be literally anything https://www.mediawiki.org/wiki/Manual:Page_content_models
Therefore, it's probably a wrong approach to parse the target page's Wikitext, as it might not be Wikitext, but something else entirely such as Markdown. So, the correct approach should be to pull the target page's HTML, run through that and find and `<a id="foo"/>` or `<a name="bar"/>` tags, store them as a list in an array, including the first entry of `Top`, which is always allowed.
We then compare the section heading to the array, and throw an error if it doesn't exist.
It's important that both normal text and percent encoding forms are recognised, so `?` and `%3F` would be equivalent.