Skip to content

Commit 06342f4

Browse files
authored
Xray 129870 python hyphens fix (#609)
1 parent 30c2fe0 commit 06342f4

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

commands/curation/curationaudit.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -955,18 +955,31 @@ func getUrlNameAndVersionByTech(tech techutils.Technology, node *xrayUtils.Graph
955955
}
956956

957957
func getPythonNameVersion(id string, downloadUrlsMap map[string]string) (downloadUrls []string, name, version string) {
958-
if downloadUrlsMap != nil {
959-
if dl, ok := downloadUrlsMap[id]; ok {
960-
downloadUrls = []string{dl}
961-
} else {
962-
log.Warn(fmt.Sprintf("couldn't find download url for node id %s", id))
963-
}
958+
idWithoutPrefix := strings.TrimPrefix(id, python.PythonPackageTypeIdentifier)
959+
parts := strings.Split(idWithoutPrefix, ":")
960+
if len(parts) < 2 {
961+
log.Debug(fmt.Sprintf("Package %s has unexpected format", id))
962+
return
964963
}
965-
id = strings.TrimPrefix(id, python.PythonPackageTypeIdentifier)
966-
allParts := strings.Split(id, ":")
967-
if len(allParts) >= 2 {
968-
name = allParts[0]
969-
version = allParts[1]
964+
965+
name, version = parts[0], parts[1]
966+
967+
if downloadUrlsMap == nil {
968+
return
969+
}
970+
if dl, ok := downloadUrlsMap[id]; ok {
971+
downloadUrls = []string{dl}
972+
return
973+
}
974+
975+
// Python package names are case-insensitive and treat hyphens/underscores as equivalentl.
976+
// The download URLs map uses normalized names, so we normalize the id to find a match.
977+
normalizedName := strings.ReplaceAll(strings.ToLower(strings.TrimSpace(parts[0])), "-", "_")
978+
normalizedId := python.PythonPackageTypeIdentifier + normalizedName + ":" + strings.TrimSpace(parts[1])
979+
if dl, ok := downloadUrlsMap[normalizedId]; ok {
980+
downloadUrls = []string{dl}
981+
} else {
982+
log.Warn(fmt.Sprintf("couldn't find download url for node id %s in report.json", id))
970983
}
971984
return
972985
}

commands/curation/curationaudit_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,10 @@ func getTestCasesForDoCurationAudit() []testCase {
704704
"pip": filepath.Join("resources", "pip-resp"),
705705
"pexpect": filepath.Join("resources", "pexpect-resp"),
706706
"ptyprocess": filepath.Join("resources", "ptyprocess-resp"),
707+
"typing-extensions": filepath.Join("resources", "typing-extensions-resp"),
707708
"pexpect-4.8.0-py2.py3-none-any.whl": filepath.Join("resources", "pexpect-4.8.0-py2.py3-none-any.whl"),
708709
"ptyprocess-0.7.0-py2.py3-none-any.whl": filepath.Join("resources", "ptyprocess-0.7.0-py2.py3-none-any.whl"),
710+
"typing_extensions-4.15.0-py3-none-any.whl": filepath.Join("resources", "typing_extensions-4.15.0-py3-none-any.whl"),
709711
},
710712
requestToFail: map[string]bool{
711713
"/api/pypi/pypi-remote/packages/packages/39/7b/88dbb785881c28a102619d46423cb853b46dbccc70d3ac362d99773a78ce/pexpect-4.8.0-py2.py3-none-any.whl": false,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pexpect==4.8.0
1+
pexpect==4.8.0
2+
typing-extensions==4.15.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Simple Index</title>
6+
<meta name="api-version" value="2" />
7+
</head>
8+
9+
<body>
10+
<a href="../../packages/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl#sha256=f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"
11+
rel="internal">typing_extensions-4.15.0-py3-none-any.whl</a>
12+
</body>
13+
14+
</html>

0 commit comments

Comments
 (0)