From 1cb5a8401b603009aa0d6d06769ee8599127dc0e Mon Sep 17 00:00:00 2001 From: vtino17 Date: Tue, 21 Jul 2026 10:56:42 +0700 Subject: [PATCH 1/2] Fix result counter accumulating across usernames The result counter used a module-level global variable (globvar) that was never reset between username scans. When scanning multiple usernames, the count for each subsequent user included results from all previous ones. Fix: move counter to instance attribute (_result_count) initialized in QueryNotifyPrint.__init__, replacing the fragile module-level global. Fixes #2990 --- pr-body.md | 7 +++++++ sherlock_project/notify.py | 12 ++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 pr-body.md diff --git a/pr-body.md b/pr-body.md new file mode 100644 index 0000000000..1ebc5c10a1 --- /dev/null +++ b/pr-body.md @@ -0,0 +1,7 @@ +## Fixes #2992 + +**Problem:** Passing `--output results.txt` without `--txt` creates no output file and shows no error. + +**Root cause:** The write block is guarded exclusively by `args.output_txt`, but `result_file` is already correctly set by `args.output`. + +**Fix:** Change condition from `if args.output_txt:` to `if args.output_txt or args.output:` diff --git a/sherlock_project/notify.py b/sherlock_project/notify.py index ab6f5a3866..5472c17974 100644 --- a/sherlock_project/notify.py +++ b/sherlock_project/notify.py @@ -7,10 +7,6 @@ from colorama import Fore, Style import webbrowser -# Global variable to count the number of results. -globvar = 0 - - class QueryNotify: """Query Notify Object. @@ -132,6 +128,7 @@ def __init__(self, result=None, verbose=False, print_all=False, browse=False): self.verbose = verbose self.print_all = print_all self.browse = browse + self._result_count = 0 def start(self, message): @@ -169,9 +166,8 @@ def countResults(self): Return Value: The number of results by the time we call the function. """ - global globvar - globvar += 1 - return globvar + self._result_count += 1 + return self._result_count def update(self, result): """Notify Update. @@ -258,7 +254,7 @@ def finish(self, message="The processing has been finished."): Return Value: Nothing. """ - NumberOfResults = self.countResults() - 1 + NumberOfResults = self._result_count print(Style.BRIGHT + Fore.GREEN + "[" + Fore.YELLOW + "*" + From e433aa4e449cd02e3551f1503abbb6240e6f9228 Mon Sep 17 00:00:00 2001 From: Valentino Saputra Date: Tue, 11 Aug 2026 06:31:57 +0700 Subject: [PATCH 2/2] test: cover per-notifier result counts --- pr-body.md | 7 ------- tests/test_notify.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) delete mode 100644 pr-body.md create mode 100644 tests/test_notify.py diff --git a/pr-body.md b/pr-body.md deleted file mode 100644 index 1ebc5c10a1..0000000000 --- a/pr-body.md +++ /dev/null @@ -1,7 +0,0 @@ -## Fixes #2992 - -**Problem:** Passing `--output results.txt` without `--txt` creates no output file and shows no error. - -**Root cause:** The write block is guarded exclusively by `args.output_txt`, but `result_file` is already correctly set by `args.output`. - -**Fix:** Change condition from `if args.output_txt:` to `if args.output_txt or args.output:` diff --git a/tests/test_notify.py b/tests/test_notify.py new file mode 100644 index 0000000000..864c337597 --- /dev/null +++ b/tests/test_notify.py @@ -0,0 +1,28 @@ +from sherlock_project.notify import QueryNotifyPrint +from sherlock_project.result import QueryResult, QueryStatus + + +def claimed_result(): + return QueryResult( + username='example', + site_name='Example', + site_url_user='https://example.com/example', + status=QueryStatus.CLAIMED, + ) + + +def test_result_count_is_scoped_to_each_notifier(capsys): + first = QueryNotifyPrint() + first.update(claimed_result()) + first.update(claimed_result()) + first.finish() + + assert ' 2 ' in capsys.readouterr().out + assert first._result_count == 2 + + second = QueryNotifyPrint() + second.update(claimed_result()) + second.finish() + + assert ' 1 ' in capsys.readouterr().out + assert second._result_count == 1