Skip to content

Commit

Permalink
Prevent initial crash by changes in spellchecking
Browse files Browse the repository at this point in the history
Signed-off-by: TheJackiMonster <[email protected]>
  • Loading branch information
TheJackiMonster committed Dec 7, 2023
1 parent 3707d9e commit 82fe326
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions manuskript/functions/spellchecker.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -201,10 +201,13 @@ def checkText(self, text):
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

Expand All @@ -215,7 +218,7 @@ def checkText(self, text):
# ((?:[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)):

Expand Down

0 comments on commit 82fe326

Please sign in to comment.