'Why does a .cpp file get wrong extension when downloaded with data download anchor?

I have the following HTML code:

<a href="data:text/x-c;charset=utf-8,struct%20example%20%7B%0A%09int%20number%20%3D%205%3B%0A%7D%3B"
   download="example.cpp" target="_blank">Download a struct stub</a>

but for some reason, clicking this anchor results downloading an example.cp file and not example.cpp. I think I've checked everything. For instance, for .json files it works correctly. Also text/x-c is the right Content-Type for .cpp files. I've also tried with text/plain, but it still kept getting changed to .cp. Why does this happen and is there a workaround to it? I'm using Google Chrome.



Solution 1:[1]

As of April 2022: I have the same issue when trying to download .cpp files using Google Chrome.

Switching to Safari and Firefox works for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Huyen