MathJax wrongly rendered when used as alt text for image

When MathJax is used within the alt text of an image, like this:

![test $2$][1]


the rendered result will show the MathJax 'outside' the image:

Interestingly, the preview renders the image correctly, presumably because it doesn't try to render the MathJax:

There have been some recent changes to the server-side code in order to insert <span class="math-container">...</span> around MathJax delimiters (I'm not sure why, but I spect it is so that other parts of the system can recognize the math for things like hot questions and the difference displays for past edits). It seems that the code that is doing this is produce incorrect results, as the page you linked to includes
<img src="https://cdn.sstatic.net/Sites/math/img/logo.svg?v=2ad3f9715b74" alt="test <span class="math-container">$2$</span>"></p>

which is invalid HTML. The quotation marks for the math-container element end the quotation marks for the alt attribute, which means the > before $2$ is parsed as the end of the img tag, and so the $2$ now falls outside the alt text, and is displayed by MathJax. This doesn't happen in the preview because the math-container tags are not inserted during previews.