Ignore zero-padding for non-finite floating points
Fixes #2305.

Is there a better way to check for the `0`-padding-option than what I wrote?
{"label": "fmtlib:master", "ref": "master", "sha": "bc13c6de390751ecf8daa1b1ce8f775d104fdc65"}
From the documentation (emphasis mine):
> Preceding the width field by a zero ('0') character enables sign-aware zero-padding for numeric types. It forces the padding to be placed after the sign or base (if any) but before the digits. This is used for printing fields in the form ‘+000000120’. This option is only valid for numeric types and ***it has no effect on formatting of infinity and NaN.***

```CPP
fmt::print("'{:+06}'\n", NAN);
// output: '00+nan'
```

https://godbolt.org/z/Pnh33M6r6
Numeric zero fill is applied to inf/nan
diff --git a/include/fmt/core.h b/include/fmt/core.h
index 9db39267a3d2..20d4d172efab 100644
--- a/include/fmt/core.h
+++ b/include/fmt/core.h
@@ -1948,7 +1948,7 @@ template <typename Char> class specs_setter {
   FMT_CONSTEXPR void on_localized() { specs_.localized = true; }
 
   FMT_CONSTEXPR void on_zero() {
-    specs_.align = align::numeric;
+    if (specs_.align == align::none) specs_.align = align::numeric;
     specs_.fill[0] = Char('0');
   }
 
diff --git a/include/fmt/format.h b/include/fmt/format.h
index 6df5d849de52..63bac1466d59 100644
--- a/include/fmt/format.h
+++ b/include/fmt/format.h
@@ -1584,13 +1584,17 @@ FMT_CONSTEXPR OutputIt write(OutputIt out, const Char* s,
 
 template <typename Char, typename OutputIt>
 OutputIt write_nonfinite(OutputIt out, bool isinf,
-                         const basic_format_specs<Char>& specs,
+                         basic_format_specs<Char> specs,
                          const float_specs& fspecs) {
   auto str =
       isinf ? (fspecs.upper ? "INF" : "inf") : (fspecs.upper ? "NAN" : "nan");
   constexpr size_t str_size = 3;
   auto sign = fspecs.sign;
   auto size = str_size + (sign ? 1 : 0);
+  // Replace '0'-padding with space for non-finite values.
+  const bool is_zero_fill =
+      specs.fill.size() == 1 && *specs.fill.data() == static_cast<Char>('0');
+  if (is_zero_fill) specs.fill[0] = static_cast<Char>(' ');
   return write_padded(out, specs, size, [=](reserve_iterator<OutputIt> it) {
     if (sign) *it++ = static_cast<Char>(data::signs[sign]);
     return copy_str<Char>(str, str + str_size, it);

diff --git a/test/format-test.cc b/test/format-test.cc
index cbed4984a2d0..38399788af1a 100644
--- a/test/format-test.cc
+++ b/test/format-test.cc
@@ -1272,10 +1272,16 @@ TEST(format_test, format_nan) {
   double nan = std::numeric_limits<double>::quiet_NaN();
   EXPECT_EQ("nan", fmt::format("{}", nan));
   EXPECT_EQ("+nan", fmt::format("{:+}", nan));
-  if (std::signbit(-nan))
+  EXPECT_EQ("  +nan", fmt::format("{:+06}", nan));
+  EXPECT_EQ("+nan  ", fmt::format("{:<+06}", nan));
+  EXPECT_EQ(" +nan ", fmt::format("{:^+06}", nan));
+  EXPECT_EQ("  +nan", fmt::format("{:>+06}", nan));
+  if (std::signbit(-nan)) {
     EXPECT_EQ("-nan", fmt::format("{}", -nan));
-  else
+    EXPECT_EQ("  -nan", fmt::format("{:+06}", -nan));
+  } else {
     fmt::print("Warning: compiler doesn't handle negative NaN correctly");
+  }
   EXPECT_EQ(" nan", fmt::format("{: }", nan));
   EXPECT_EQ("NAN", fmt::format("{:F}", nan));
   EXPECT_EQ("nan    ", fmt::format("{:<7}", nan));
@@ -1288,6 +1294,11 @@ TEST(format_test, format_infinity) {
   EXPECT_EQ("inf", fmt::format("{}", inf));
   EXPECT_EQ("+inf", fmt::format("{:+}", inf));
   EXPECT_EQ("-inf", fmt::format("{}", -inf));
+  EXPECT_EQ("  +inf", fmt::format("{:+06}", inf));
+  EXPECT_EQ("  -inf", fmt::format("{:+06}", -inf));
+  EXPECT_EQ("+inf  ", fmt::format("{:<+06}", inf));
+  EXPECT_EQ(" +inf ", fmt::format("{:^+06}", inf));
+  EXPECT_EQ("  +inf", fmt::format("{:>+06}", inf));
   EXPECT_EQ(" inf", fmt::format("{: }", inf));
   EXPECT_EQ("INF", fmt::format("{:F}", inf));
   EXPECT_EQ("inf    ", fmt::format("{:<7}", inf));

{"format-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"compile-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ostream-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "ranges-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "core-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "scan-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "color-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "chrono-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "args-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "gtest-extra-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "assert-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "posix-mock-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "printf-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "wchar-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "format-impl-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "enforce-checks-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}, "os-test": {"run": "PASS", "test": "PASS", "fix": "PASS"}}
{"format-test": {"run": "PASS", "test": "NONE", "fix": "PASS"}}
{"passed_count": 17, "failed_count": 0, "skipped_count": 0, "passed_tests": ["format-test", "args-test", "gtest-extra-test", "compile-test", "ostream-test", "ranges-test", "assert-test", "posix-mock-test", "core-test", "printf-test", "color-test", "scan-test", "format-impl-test", "wchar-test", "enforce-checks-test", "os-test", "chrono-test"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 16, "failed_count": 0, "skipped_count": 0, "passed_tests": ["args-test", "gtest-extra-test", "compile-test", "ostream-test", "ranges-test", "assert-test", "posix-mock-test", "core-test", "printf-test", "color-test", "scan-test", "format-impl-test", "wchar-test", "enforce-checks-test", "os-test", "chrono-test"], "failed_tests": [], "skipped_tests": []}
{"passed_count": 17, "failed_count": 0, "skipped_count": 0, "passed_tests": ["format-test", "args-test", "gtest-extra-test", "compile-test", "ostream-test", "ranges-test", "assert-test", "posix-mock-test", "core-test", "printf-test", "color-test", "scan-test", "format-impl-test", "wchar-test", "enforce-checks-test", "os-test", "chrono-test"], "failed_tests": [], "skipped_tests": []}