fix: parsing metadata with inline licenses (#2806)

The wheel `METADATA` parsing implemented in 1.4 missed the fact
that whitespace is significant and sometimes License is included
inline in the `METADATA` file itself.

This change ensures that we stop parsing the `METADATA` file only
on first completely empty line.

Fixes https://github.com/bazel-contrib/rules_python/issues/2796

---------

Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
(cherry picked from commit 1d69ad68d7959570acde61d8705f1f437c0691b0)
diff --git a/python/private/pypi/whl_metadata.bzl b/python/private/pypi/whl_metadata.bzl
index 8a86ffb..cf2d51a 100644
--- a/python/private/pypi/whl_metadata.bzl
+++ b/python/private/pypi/whl_metadata.bzl
@@ -52,7 +52,7 @@
         "version": "",
     }
     for line in contents.strip().split("\n"):
-        if not line.strip():
+        if not line:
             # Stop parsing on first empty line, which marks the end of the
             # headers containing the metadata.
             break
diff --git a/tests/pypi/whl_metadata/whl_metadata_tests.bzl b/tests/pypi/whl_metadata/whl_metadata_tests.bzl
index 4acbc92..329423a 100644
--- a/tests/pypi/whl_metadata/whl_metadata_tests.bzl
+++ b/tests/pypi/whl_metadata/whl_metadata_tests.bzl
@@ -140,6 +140,37 @@
 
 _tests.append(_test_parse_metadata_all)
 
+def _test_parse_metadata_multiline_license(env):
+    got = _parse_whl_metadata(
+        env,
+        # NOTE: The trailing whitespace here is meaningful as an empty line
+        # denotes the end of the header.
+        contents = """\
+Name: foo
+Version: 0.0.1
+License: some License
+        
+        some line
+        
+        another line
+        
+Requires-Dist: bar; extra == "all"
+Provides-Extra: all
+
+Requires-Dist: this will be ignored
+""",
+    )
+    got.name().equals("foo")
+    got.version().equals("0.0.1")
+    got.requires_dist().contains_exactly([
+        "bar; extra == \"all\"",
+    ])
+    got.provides_extra().contains_exactly([
+        "all",
+    ])
+
+_tests.append(_test_parse_metadata_multiline_license)
+
 def whl_metadata_test_suite(name):  # buildifier: disable=function-docstring
     test_suite(
         name = name,