Skip to content

Commit 7e24835

Browse files
committed
Fix cgit regex pattern
Add more test Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent 24fdf1d commit 7e24835

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/packageurl/contrib/url2purl.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ def build_cgit_purl(url):
753753
Return a PackageURL object from a cgit url
754754
For example:
755755
https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=74770b1fd2be612f9c2cf807db81fcdcc35e6560
756+
https://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev.git/commit/?h=for-next&id=bd771cf5c4254511cc4abb88f3dab3bd58bdf8e8
756757
https://cgit.git.savannah.gnu.org/cgit/uddf.git/commit/?id=98c41e131dc952aee43d4ec392b80ca4c426be8d
757758
https://gitweb.gentoo.org/dev/darkside.git/commit/?id=8d4b0836f3b6ab7075212926d9aad0b50246d825
758759
"""
@@ -765,8 +766,10 @@ def build_cgit_purl(url):
765766
r"(?:\.git)?"
766767
r"/commit/"
767768
r"(?:[^?]+)?"
768-
r"\?id="
769-
r"(?P<version>[0-9a-fA-F]{7,64})/?$"
769+
r"\?.*?"
770+
r"\bid="
771+
r"(?P<version>[0-9a-fA-F]{7,64})"
772+
r"(?:&.*)?$"
770773
)
771774

772775
commit_match = re.search(cgit_project_pattern, url)

tests/contrib/data/url2purl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
"https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/net/core/sock.c?id=9d538fa60bad4f7b23193c89e843797a1cf71ef3": "pkg:generic/git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux@9d538fa60bad4f7b23193c89e843797a1cf71ef3",
289289
"https://cgit.git.savannah.gnu.org/cgit/uddf.git/commit/?id=98c41e131dc952aee43d4ec392b80ca4c426be8d": "pkg:generic/cgit.git.savannah.gnu.org/cgit/uddf@98c41e131dc952aee43d4ec392b80ca4c426be8d",
290290
"https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git/commit/?id=7457fe9541b5162f285454947448d553a5d5a531": "pkg:generic/git.kernel.org/pub/scm/virt/kvm/mst/qemu@7457fe9541b5162f285454947448d553a5d5a531",
291+
"https://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev.git/commit/?h=for-next&id=bd771cf5c4254511cc4abb88f3dab3bd58bdf8e8": "pkg:generic/git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev@bd771cf5c4254511cc4abb88f3dab3bd58bdf8e8",
291292

292293
"https://gitweb.gentoo.org/dev/darkside.git/commit/?id=8d4b0836f3b6ab7075212926d9aad0b50246d825": "pkg:generic/gitweb.gentoo.org/dev/darkside@8d4b0836f3b6ab7075212926d9aad0b50246d825",
293294
"https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f73ae47c5e48010f504f3f55567152258f3013ae": "pkg:generic/gitweb.gentoo.org/repo/gentoo@f73ae47c5e48010f504f3f55567152258f3013ae",

0 commit comments

Comments
 (0)