Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions bin/idstack-learnings-search
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ if command -v python3 &>/dev/null; then
python3 -c "
import json, sys

sources = '$SOURCES'.split()
type_filter = '$TYPE'
keyword = '$KEYWORD'.lower()
limit = $LIMIT
sources = sys.argv[1].split() if len(sys.argv) > 1 else []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of .split() on sys.argv[1] assumes that file paths in $SOURCES do not contain spaces. If a path contains a space (e.g., if $HOME contains a space), it will be incorrectly split into multiple invalid source entries. While this matches the previous behavior, it remains a limitation for robustness.

type_filter = sys.argv[2] if len(sys.argv) > 2 else ''
keyword = sys.argv[3].lower() if len(sys.argv) > 3 else ''
try:
limit = int(sys.argv[4]) if len(sys.argv) > 4 else 3

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Python, a slice like matches[-limit:] (used on line 73) returns the entire list when limit is 0, rather than an empty list. If the intention is for --limit 0 to return no results (consistent with the behavior of tail -0), you should handle the zero case explicitly in the Python logic.

except ValueError:
limit = 3

matches = []
for src in sources:
Expand All @@ -69,7 +72,7 @@ for src in sources:
# Local learnings first (take precedence), then global
for m in matches[-limit:]:
print(m)
" 2>/dev/null || {
" "$SOURCES" "$TYPE" "$KEYWORD" "$LIMIT" 2>/dev/null || {
# Fallback: basic grep
if [ -n "$KEYWORD" ]; then
cat $SOURCES 2>/dev/null | grep -i "$KEYWORD" | tail -"$LIMIT"
Expand Down