From 52004d21fb4f783e9be90af17c7bbf91a2980a4d Mon Sep 17 00:00:00 2001 From: Mike Fiedler Date: Wed, 12 Mar 2025 13:49:28 -0400 Subject: [PATCH] fix: false positive on swapped words Surfaced false positives in this check with some recent upload testing. Since the permutations can reconstruct the project name to the same as the input, verify that the reconstructed name differs from input. Signed-off-by: Mike Fiedler --- tests/unit/packaging/test_typosnyper.py | 1 + warehouse/packaging/typosnyper.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/packaging/test_typosnyper.py b/tests/unit/packaging/test_typosnyper.py index 9ad021d15734..1cf37a24f742 100644 --- a/tests/unit/packaging/test_typosnyper.py +++ b/tests/unit/packaging/test_typosnyper.py @@ -29,6 +29,7 @@ ("dateutil-python", ("swapped_words", "python-dateutil")), ("numpi", ("common_typos", "numpy")), ("requestz", ("common_typos", "requests")), + ("python-dateutil", None), # Pass, swapped_words same as original ], ) def test_typo_check_name(name, expected): diff --git a/warehouse/packaging/typosnyper.py b/warehouse/packaging/typosnyper.py index 91ffd9988b07..33b21f8f4442 100644 --- a/warehouse/packaging/typosnyper.py +++ b/warehouse/packaging/typosnyper.py @@ -381,7 +381,7 @@ def _swapped_words(project_name: str, corpus: set[str]) -> TypoCheckMatch: # Join the words using `-` to create a new name reconstructed = "-".join(p) # If the new name is in the list of popular names, return it - if reconstructed in corpus: + if reconstructed != project_name and reconstructed in corpus: return "swapped_words", reconstructed return None