Skip to content

Commit

Permalink
[search] handle no rows and invalid regex
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Nov 19, 2023
1 parent 01df944 commit 1ee29b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions visidata/movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def rotateRange(n, idx, reverse=False):
'Wraps an iter starting from idx. Yields indices from idx to n and then 0 to idx.'
if n == 0: return []
if reverse:
rng = range(idx-1, -1, -1)
rng2 = range(n-1, idx-1, -1)
Expand Down
7 changes: 6 additions & 1 deletion visidata/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def findMatchingColumn(sheet, row, columns, func):
if regex_flags is None:
regex_flags = sheet.options.regex_flags # regex_flags defined in features.regex
flagbits = sum(getattr(re, f.upper()) for f in regex_flags)
vd.searchContext["regex"] = re.compile(regex, flagbits) or vd.error('invalid regex: %s' % regex)
try:
compiled_re = re.compile(regex, flagbits)
except re.error as e:
vd.searchContext["regex"] = None # make future calls to search-next fail
vd.error('invalid regex: %s' % e.msg)
vd.searchContext["regex"] = compiled_re

regex = vd.searchContext.get("regex") or vd.fail("no regex")

Expand Down

0 comments on commit 1ee29b9

Please # to comment.