Name resolution APIs and libraries SHOULD recognize
localhost names as special and SHOULD always return
the IP loopback address for address queries and
negative responses for all other query types. Name
resolution APIs SHOULD NOT send queries for localhost
names to their configured caching DNS server(s).
A few notes:1) The use of "the IP loopback address" is a bit weird in IPv4, of course.
2) It's hard to know which loopback address to return from an API without violating the "SHOULD NOT" part of this item.
There's really no way to win here. In theory Firefox could do the resolution as normal and then if it doesn't come back as loopback replace it with 127.0.0.1. That would be perfectly within the letter of the RFC, since none of the stuff above it MUST-level requirements, but probably not really within its spirit, since it would violate the "SHOULD NOT" bit.
Note that Firefox is not alone here; Chrome has the same behavior last I checked. https://bugzilla.mozilla.org/show_bug.cgi?id=1220810#c28 is a comment from one of the networking/security folks at Chrome about this precise issue, in case it's of interest.