Skip to content

Commit

Permalink
Merge pull request #37 from conitrade/hotfix/sqlite-udf-regex
Browse files Browse the repository at this point in the history
ensure None values do not crash SQLite regex UDF
  • Loading branch information
wagga40 committed Sep 19, 2022
2 parents 403ce24 + 9ecfbcb commit 8e53882
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion zircolite.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,17 @@ def createConnection(self, db):
try:
conn = sqlite3.connect(db)
conn.row_factory = sqlite3.Row # Allows to get a dict

def udf_regex(x, y):
if y is None:
return 0
if re.search(x, y):
return 1
else:
return 0

conn.create_function(
"regexp", 2, lambda x, y: 1 if re.search(x, y) else 0
"regexp", 2, udf_regex
) # Allows to use regex in SQlite
except Error as e:
self.logger.error(f"{Fore.RED} [-] {e}")
Expand Down

0 comments on commit 8e53882

Please sign in to comment.