Repository: hesa/foss-licenses (language: python)

Issue:
License alias order incorrect
License aliases are supposed to be replaced longest in size first.

Current solution (license_db.py):
`        for needle in reversed(collections.OrderedDict(sorted(needles.items()))):`
does not do that. Replace the above with:
`        for needle in reversed(collections.OrderedDict(sorted(needles.items(), key = lambda x : len(x[0])))):`

and things should be fine


Discussion / hints:

Fix patch:
diff --git a/python/flame/license_db.py b/python/flame/license_db.py
index 647abcf..ee10b7a 100644
--- a/python/flame/license_db.py
+++ b/python/flame/license_db.py
@@ -135,7 +135,7 @@ def __identify_license(self, name):
 
     def __update_license_expression_helper(self, needles, needle_tag, license_expression, allow_letter=False):
         replacements = []
-        for needle in reversed(collections.OrderedDict(sorted(needles.items()))):
+        for needle in reversed(collections.OrderedDict(sorted(needles.items(), key=lambda x: len(x[0])))):
             if allow_letter:
                 reg_exp = r'( |\(|^|\)|\||/)%s( |$|\)|\||&|[a-zA-Z])' % re.escape(needle)
                 extra_add = " "


Test patch:
diff --git a/tests/licenses/GPL-2.0-or-later.json b/tests/licenses/GPL-2.0-or-later.json
index 106b667..d3ffb07 100644
--- a/tests/licenses/GPL-2.0-or-later.json
+++ b/tests/licenses/GPL-2.0-or-later.json
@@ -9,6 +9,7 @@
     "aliases": [
         "GPLv2+",
         "GPL2+",
-        "GPL (v2 or later)"
+        "GPL (v2 or later)",
+        "GNU General Public License v2 or later (GPLv2+)"
     ]
 }
diff --git a/tests/python/test_ldb.py b/tests/python/test_ldb.py
index 805825d..b659832 100644
--- a/tests/python/test_ldb.py
+++ b/tests/python/test_ldb.py
@@ -18,18 +18,18 @@
 def test_alias_list():
     # list of all aliases
     aliases = fl.alias_list()
-    assert len(aliases) == 6
+    assert len(aliases) == 7
 
 def test_alias_list_gpl():
     # list of all aliases with license with GPL
     aliases = fl.alias_list("GPL")
-    assert len(aliases) == 3
+    assert len(aliases) == 4
 
 def test_aliases():
     # list of all aliases for GPL-2.0-or-later
     aliases = fl.aliases("GPL-2.0-or-later")
     aliases.sort()
-    assert aliases == [ "GPL (v2 or later)", "GPL2+",  "GPLv2+" ]
+    assert aliases == [ "GNU General Public License v2 or later (GPLv2+)", "GPL (v2 or later)", "GPL2+",  "GPLv2+" ]
 
 def test_aliases_bad_input():
     # make sure bad input raises exception
@@ -60,9 +60,11 @@ def test_with_license_2():
     lic = fl.expression_license("BSD3 w/SomeException")
     assert lic['identified_license'] == "BSD-3-Clause WITH SomeException"
 
-def test_with_license_3():
-    lic = fl.expression_license("BSD3 with SomeException")
-    assert lic['identified_license'] == "BSD-3-Clause WITH SomeException"
+def test_with_license_with_parent():
+    """Test issue 69"""
+    lic = fl.expression_license("GNU General Public License v2 or later (GPLv2+)")
+    assert lic['identified_license'] == "GPL-2.0-or-later"
+    pass
 
 def test_expression_license_types():
     lic = fl.expression_license("BSD-3-Clause and BSD3")