From 82fe3262af2d7c506488f576acaafba5bcad2f73 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Thu, 7 Dec 2023 19:36:37 +0100 Subject: [PATCH] Prevent initial crash by changes in spellchecking Signed-off-by: TheJackiMonster --- manuskript/functions/spellchecker.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/manuskript/functions/spellchecker.py b/manuskript/functions/spellchecker.py index 64afa67..54fc53a 100644 --- a/manuskript/functions/spellchecker.py +++ b/manuskript/functions/spellchecker.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # --!-- coding: utf8 --!-- -import os, gzip, json, glob, re +import os, gzip, json, glob, re, string from PyQt5.QtCore import QLocale from collections import OrderedDict from manuskript.functions import writablePath @@ -201,10 +201,13 @@ class BasicDictionary: mispelled = self.isMisspelled(word) if mispelled == False: continue + punctuation = string.punctuation.replace('-', '') + + FALSE_POSITIVE = r'^[^\w]|([^{}])$'.format(punctuation) + #inorder to prevent apostrophes causing false positives and keep the same functionality otherwise, #check that the word doesn't have any additional punctuation on it. - if re.match("^[^\w]|([\p{P}'])$", word): - + if re.match(FALSE_POSITIVE, word): # ^[^\w] checks that it doesn't start with a word character # ([\p{P}'])$ checks it doesn't end with punctuation characters @@ -215,7 +218,7 @@ class BasicDictionary: # ((?:[a-zA-Z]|\')+) greedily matches for letters and apostrophes temp = re.match(apostrophe_WORDS, word) - mispelled = self.isMisspelled(temp.group(1)) + mispelled = self.isMisspelled(temp.group(1)) if temp else False if (mispelled and not self.isCustomWord(word)):