Bulk metadata search and replace: Fallback to V0 regex mode for expressions that dont parse with V1

This commit is contained in:
Kovid Goyal 2020-10-05 08:06:57 +05:30
parent 0e09b58efb
commit 02095fcf81
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -973,7 +973,7 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
def s_r_paint_results(self, txt):
self.s_r_error = None
self.s_r_set_colors()
flags = regex.VERSION1 | regex.FULLCASE | regex.UNICODE
flags = regex.FULLCASE | regex.UNICODE
if self.case_sensitive.isChecked():
flags |= regex.IGNORECASE
@ -983,9 +983,12 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
if not stext:
raise Exception(_('You must specify a search expression in the "Search for" field'))
if self.search_mode.currentIndex() == 0:
self.s_r_obj = regex.compile(regex.escape(stext), flags)
self.s_r_obj = regex.compile(regex.escape(stext), flags | regex.V1)
else:
self.s_r_obj = regex.compile(stext, flags)
try:
self.s_r_obj = regex.compile(stext, flags | regex.V1)
except regex.error:
self.s_r_obj = regex.compile(stext, flags)
except Exception as e:
self.s_r_obj = None
self.s_r_error = e