From 34fe6c2ff6a9688f6e0114190cbb599f7aa6d942 Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Thu, 10 Feb 2022 19:12:37 -0800 Subject: [PATCH] Update PyPI route pattern in url2purl #76 * Handle PyPI package names with hyphens and dots in it * Update test data and expectations Signed-off-by: Jono Yang --- CHANGELOG.rst | 1 + src/packageurl/contrib/url2purl.py | 7 +++++-- tests/contrib/data/url2purl.json | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c2e081e..5140030 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,7 @@ Changelog - Do not create a generic PackageURL for URLs without a path in url2purl #72 - Increase the name field size for packageurl.contrib.django.models.PackageURLMixin to 255 #73 - Use project name as the Package name when creating generic sourceforge PackageURLs #74 +- Update PyPI route pattern in url2purl to handle different file name formats #76 0.9.7 (2022-02-07) ------------------ diff --git a/src/packageurl/contrib/url2purl.py b/src/packageurl/contrib/url2purl.py index 06d560b..4a64135 100644 --- a/src/packageurl/contrib/url2purl.py +++ b/src/packageurl/contrib/url2purl.py @@ -263,9 +263,12 @@ def build_rubygems_purl(uri): # https://pypi.python.org/packages/source/a/anyjson/anyjson-0.3.3.tar.gz +# https://pypi.python.org/packages/2.6/t/threadpool/threadpool-1.2.7-py2.6.egg +# https://pypi.python.org/packages/any/s/setuptools/setuptools-0.6c11-1.src.rpm +# https://files.pythonhosted.org/packages/84/d8/451842a5496844bb5c7634b231a2e4caf0d867d2e25f09b840d3b07f3d4b/multi_key_dict-2.0.win32.exe pypi_pattern = ( - r"(?P.+)-(?P.+)" - r"\.(zip|tar.gz|tar.bz2|.tgz)$" + r"(?P(\w\.?)+(-\w+)*)-(?P.+)" + r"\.(zip|tar.gz|tar.bz2|tgz|egg|rpm|exe)$" ) # This pattern can be found in the following locations: diff --git a/tests/contrib/data/url2purl.json b/tests/contrib/data/url2purl.json index 9ed81e5..c560120 100644 --- a/tests/contrib/data/url2purl.json +++ b/tests/contrib/data/url2purl.json @@ -131,6 +131,12 @@ "https://pypi.python.org/packages/f6/ae/bbc6a204f33d9d57c798fb3857a072cd14b836792244eea4b446fdb674c6/pycryptodome-3.4.7-cp27-cp27m-win32.whl#md5=78b341de1cd686077745cd9e3a93d8d3": "pkg:pypi/pycryptodome@3.4.7", "https://pypi.python.org/packages/bd/e8/ea44ba5357a0b4fd16e5fb60c355fc8722eae31b93d7597eec50f7c35a52/pycryptodome-3.4.7-cp27-cp27m-win_amd64.whl#md5=f20bb847322baf7ae24700e5cbb15e07": "pkg:pypi/pycryptodome@3.4.7", "https://pypi.python.org/packages/1e/75/8005d086cac4cc41d3b320d338972c5e5c6a21f88472f21ac9d0e031d300/pyahocorasick-1.1.4.tar.bz2#md5=ad445b6648dc06e9040705ce1ccb4384": "pkg:pypi/pyahocorasick@1.1.4", + "https://pypi.python.org/packages/2.6/t/threadpool/threadpool-1.2.7-py2.6.egg": "pkg:pypi/threadpool@1.2.7-py2.6", + "https://pypi.python.org/packages/any/s/setuptools/setuptools-0.6c11-1.src.rpm": "pkg:pypi/setuptools@0.6c11-1.src", + "https://files.pythonhosted.org/packages/84/d8/451842a5496844bb5c7634b231a2e4caf0d867d2e25f09b840d3b07f3d4b/multi_key_dict-2.0.win32.exe": "pkg:pypi/multi-key-dict@2.0.win32", + "https://pypi.python.org/packages/source/d/django-contrib-comments/django-contrib-comments-1.5.tar.gz": "pkg:pypi/django-contrib-comments@1.5", + "https://files.pythonhosted.org/packages/40/90/df4cb5541c4f5016bbbe04dd09135c7f5af294efa3421f9ab6332cf30dc2/zc.buildout.languageserver-0.6.2.tar.gz": "pkg:pypi/zc.buildout.languageserver@0.6.2", + "https://files.pythonhosted.org/packages/b0/42/cac00d0570ff45c8d3b66aa32bf1aba7a527e5908123b0164e42f6af6ae1/zc.buildout.languageserver-0.6.2-py3-none-any.whl": "pkg:pypi/zc.buildout.languageserver@0.6.2", "http://nuget.org/packages/EntityFramework/4.2.0.0": "pkg:nuget/EntityFramework@4.2.0.0", "http://www.nuget.org/packages/SharpGIS.GZipWebClient/1.2.0": "pkg:nuget/SharpGIS.GZipWebClient@1.2.0", "https://www.nuget.org/api/v2/package/Newtonsoft.Json/11.0.1": "pkg:nuget/Newtonsoft.Json@11.0.1",