add3prf.py: Support license files with extensions

Some crates place there license files in files with extensions, such as
LICENSE.txt or LICENSE-MIT.md.

We should account for extensions by removing them.

Bug: 321064939
Test: Ran script against `minimal-lexical-0.2.1` crate and added unit
      tests
Change-Id: I0c385e8209969c0900909e764460fc551f07c20c
diff --git a/scripts/add3prf.py b/scripts/add3prf.py
index 6f808ef..44a8418 100755
--- a/scripts/add3prf.py
+++ b/scripts/add3prf.py
@@ -193,8 +193,8 @@
   # Some crate like time-macros-impl uses lower case names like LICENSE-Apache.
   licenses = []
   license_file = None
-  for license_file in glob.glob("LICENSE*") + glob.glob("COPYING*") + glob.glob("UNLICENSE"):
-    lowered_name = license_file.lower()
+  for license_file in glob.glob("LICENSE*") + glob.glob("COPYING*") + glob.glob("UNLICENSE*"):
+    lowered_name = os.path.splitext(license_file.lower())[0]
     if lowered_name == "license-apache":
       licenses.append(License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file))
     elif lowered_name == "license-mit":
diff --git a/scripts/add3prf_test.py b/scripts/add3prf_test.py
index 32d5c7a..a75b31f 100755
--- a/scripts/add3prf_test.py
+++ b/scripts/add3prf_test.py
@@ -82,6 +82,15 @@
     self.assertEqual(preferred_license.group, add3prf.LicenseGroup.PERMISSIVE)
     self.assertEqual(preferred_license.filename, "LICENSE-0BSD")
 
+  def test_0bsd_licensefile_with_extension(self):
+    self.fs.create_file("LICENSE-0BSD.md")
+    licenses = add3prf.decide_license_type("")
+    self.assertEqual(len(licenses), 1)
+    preferred_license = licenses[0]
+    self.assertEqual(preferred_license.type, add3prf.LicenseType.ZERO_BSD)
+    self.assertEqual(preferred_license.group, add3prf.LicenseGroup.PERMISSIVE)
+    self.assertEqual(preferred_license.filename, "LICENSE-0BSD.md")
+
   def test_unlicense_license(self):
     self.fs.create_file("LICENSE")
     licenses = add3prf.decide_license_type("Unlicense")
@@ -100,6 +109,14 @@
     self.assertEqual(preferred_license.group, add3prf.LicenseGroup.PERMISSIVE)
     self.assertEqual(preferred_license.filename, "UNLICENSE")
 
+  def test_unlicense_licensefile_with_extension(self):
+    self.fs.create_file("UNLICENSE.txt")
+    licenses = add3prf.decide_license_type("")
+    self.assertEqual(len(licenses), 1)
+    preferred_license = licenses[0]
+    self.assertEqual(preferred_license.type, add3prf.LicenseType.UNLICENSE)
+    self.assertEqual(preferred_license.group, add3prf.LicenseGroup.PERMISSIVE)
+    self.assertEqual(preferred_license.filename, "UNLICENSE.txt")
 
 class AddModuleLicenseTestCase(fake_filesystem_unittest.TestCase):