Answer security round 1: 0 🔴, 2 🟡 (0 misread); read a short-option cluster with a number as recursive, and search the directory when no operand is a folder
This commit is contained in:
@@ -19,9 +19,9 @@ from command_lines.shell_command import launched, lexed, OPERATOR, resolved, sim
|
||||
# Tools that search a folder's files: grep only given an option that makes it recursive, rg and ag always.
|
||||
GREPS = frozenset({"egrep", "fgrep", "grep"})
|
||||
SEARCHERS = GREPS | {"ag", "rg"}
|
||||
RECURSIVE_GREP = re.compile(r"-[A-Za-z]*[rR][A-Za-z]*|--(?:dereference-)?recursive|--directories=recurse")
|
||||
RECURSIVE_GREP = re.compile(r"-[^-]*[rR].*|--(?:dereference-)?recursive|--directories=recurse")
|
||||
# An option that gives the pattern, so the first operand is a folder: -e and -f in a cluster, and --regexp and --file.
|
||||
PATTERN_OPTION = re.compile(r"-[A-Za-z]*[ef][A-Za-z]*|--(?:regexp|file)(?:=.*)?")
|
||||
PATTERN_OPTION = re.compile(r"-[^-]*[ef].*|--(?:regexp|file)(?:=.*)?")
|
||||
# rg's --glob and --iglob, and -g in a cluster: group 1 or 2 holds the glob when it is in the same word, else it is the next word.
|
||||
GLOB_OPTION = re.compile(r"--i?glob(?:=(.*))?|-[A-Za-z]*?g(.*)")
|
||||
# What a Grep's glob holds beyond literals, `*`, `?` and `/`: forms globbed() does not translate.
|
||||
@@ -112,13 +112,12 @@ def split(arguments: list[str]) -> tuple[list[str], list[str]]:
|
||||
|
||||
|
||||
def folders(directory: str, options: list[str], operands: list[str], home: str) -> list[str]:
|
||||
"""The folders a search reads: its operands that are folders, or the directory it runs in where none names a file or a folder. An option's value is an operand here; one that names no file or folder is dropped like any word that does not."""
|
||||
"""The folders a search reads: its operands that are folders, or the directory it runs in where none is. An option's value is an operand here; one that is no folder is dropped like any word that is none."""
|
||||
if not any(PATTERN_OPTION.fullmatch(option) for option in options):
|
||||
# The first operand is the pattern.
|
||||
operands = operands[1:]
|
||||
named = [resolved(directory, home_word(operand), home) for operand in operands]
|
||||
existing = [word for word in named if os.path.exists(word)]
|
||||
return [word for word in existing if os.path.isdir(word)] if existing else [directory]
|
||||
return [word for word in named if os.path.isdir(word)] or [directory]
|
||||
|
||||
|
||||
def globs_of(arguments: list[str]) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user