forked from rDrama/rDrama
commit
7413dcd384
|
@ -9,7 +9,7 @@ from sqlalchemy import *
|
||||||
from sqlalchemy.orm import relationship, deferred
|
from sqlalchemy.orm import relationship, deferred
|
||||||
|
|
||||||
from files.__main__ import Base
|
from files.__main__ import Base
|
||||||
from files.helpers.const import SLURS, AUTOPOLLER_ACCOUNT
|
from files.helpers.const import AUTOPOLLER_ACCOUNT
|
||||||
from files.helpers.lazy import lazy
|
from files.helpers.lazy import lazy
|
||||||
from .flags import Flag
|
from .flags import Flag
|
||||||
from ..helpers.word_censor import censor_slurs
|
from ..helpers.word_censor import censor_slurs
|
||||||
|
@ -365,8 +365,7 @@ class Submission(Base):
|
||||||
elif self.title_html: title = self.title_html
|
elif self.title_html: title = self.title_html
|
||||||
else: title = self.title
|
else: title = self.title
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
title = censor_slurs(title, v)
|
||||||
for s,r in SLURS.items(): title = title.replace(s, r)
|
|
||||||
|
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
@ -375,8 +374,7 @@ class Submission(Base):
|
||||||
if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): return 'COUNTRY CLUB MEMBERS ONLY'
|
if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): return 'COUNTRY CLUB MEMBERS ONLY'
|
||||||
else: title = self.title
|
else: title = self.title
|
||||||
|
|
||||||
if not v or v.slurreplacer:
|
title = censor_slurs(title, v)
|
||||||
for s,r in SLURS.items(): title = title.replace(s, r)
|
|
||||||
|
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ def create_slur_regex() -> Pattern[str]:
|
||||||
"""Creates the regex that will find the slurs"""
|
"""Creates the regex that will find the slurs"""
|
||||||
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
|
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
|
||||||
|
|
||||||
return re.compile(rf"(?i)(?<=\s|>)({single_words})([\s<,.])")
|
return re.compile(rf"(?i)(?<=\s|>)({single_words})(?=[\s<,.])")
|
||||||
|
|
||||||
|
|
||||||
def create_replace_map() -> Dict[str, str]:
|
def create_replace_map() -> Dict[str, str]:
|
||||||
|
@ -60,9 +60,9 @@ REPLACE_MAP = create_replace_map()
|
||||||
|
|
||||||
def sub_matcher(match: Match) -> str:
|
def sub_matcher(match: Match) -> str:
|
||||||
"""given a match returns the correct replacer string"""
|
"""given a match returns the correct replacer string"""
|
||||||
found = match.group(1)
|
found = match.group(0)
|
||||||
# if it does not find the correct capitalization, it tries the all lower, or return the original word
|
# if it does not find the correct capitalization, it tries the all lower, or return the original word
|
||||||
return (REPLACE_MAP.get(found) or REPLACE_MAP.get(found.lower()) or found) + match.group(2)
|
return REPLACE_MAP.get(found) or REPLACE_MAP.get(found.lower()) or found
|
||||||
|
|
||||||
|
|
||||||
def censor_slurs(body: str, logged_user) -> str:
|
def censor_slurs(body: str, logged_user) -> str:
|
||||||
|
|
|
@ -52,7 +52,7 @@ def test_get_permutations_slur_wiht_link_replacer():
|
||||||
"retard": "r-slur",
|
"retard": "r-slur",
|
||||||
})
|
})
|
||||||
def test_create_slur_regex():
|
def test_create_slur_regex():
|
||||||
expected = r"(?i)(?<=\s|>)(kill yourself|faggot|nig|retard)([\s<,.])"
|
expected = r"(?i)(?<=\s|>)(kill yourself|faggot|nig|retard)(?=[\s<,.])"
|
||||||
|
|
||||||
assert_that(create_slur_regex()).is_equal_to(re.compile(expected))
|
assert_that(create_slur_regex()).is_equal_to(re.compile(expected))
|
||||||
|
|
||||||
|
@ -91,19 +91,19 @@ def test_create_replace_map():
|
||||||
|
|
||||||
@patch("files.helpers.word_censor.REPLACE_MAP", {'retard': 'r-slur', 'Faggot': 'Cute twink', 'NIG': 'π'})
|
@patch("files.helpers.word_censor.REPLACE_MAP", {'retard': 'r-slur', 'Faggot': 'Cute twink', 'NIG': 'π'})
|
||||||
def test_sub_matcher():
|
def test_sub_matcher():
|
||||||
regex = re.compile(r"(?i)(?<=\s|>)(kill yourself|retard|nig|faggot)([\s<,.])")
|
regex = re.compile(r"(?i)(?<=\s|>)(kill yourself|retard|nig|faggot)(?=[\s<,.])")
|
||||||
|
|
||||||
match = regex.search("<p>retard</p>")
|
match = regex.search("<p>retard</p>")
|
||||||
assert_that(sub_matcher(match)).is_equal_to("r-slur<")
|
assert_that(sub_matcher(match)).is_equal_to("r-slur")
|
||||||
|
|
||||||
match = regex.search("<p>ReTaRd</p>")
|
match = regex.search("<p>ReTaRd</p>")
|
||||||
assert_that(sub_matcher(match)).is_equal_to("r-slur<")
|
assert_that(sub_matcher(match)).is_equal_to("r-slur")
|
||||||
|
|
||||||
match = regex.search("<p>NIG</p>")
|
match = regex.search("<p>NIG</p>")
|
||||||
assert_that(sub_matcher(match)).is_equal_to("π<")
|
assert_that(sub_matcher(match)).is_equal_to("π")
|
||||||
|
|
||||||
match = regex.search("<p>Faggot </p>")
|
match = regex.search("<p>Faggot </p>")
|
||||||
assert_that(sub_matcher(match)).is_equal_to("Cute twink ")
|
assert_that(sub_matcher(match)).is_equal_to("Cute twink")
|
||||||
|
|
||||||
|
|
||||||
@patch("files.helpers.word_censor.SLURS", {
|
@patch("files.helpers.word_censor.SLURS", {
|
||||||
|
@ -149,11 +149,6 @@ def test_censor_slurs():
|
||||||
assert_that(censor_slurs('... i Hate carp ...', None)).is_equal_to('... i love Carp ...')
|
assert_that(censor_slurs('... i Hate carp ...', None)).is_equal_to('... i love Carp ...')
|
||||||
|
|
||||||
assert_that(censor_slurs('... i hate a carp ...', None)).is_equal_to('... i hate a carp ...')
|
assert_that(censor_slurs('... i hate a carp ...', None)).is_equal_to('... i hate a carp ...')
|
||||||
assert_that(censor_slurs("""<h1 id="post-title" class="card-title post-title text-left mb-md-3">
|
|
||||||
I had a dream about this site last night
|
|
||||||
</h1>""", None)).is_equal_to("""<h1 id="post-title" class="card-title post-title text-left mb-md-3">
|
|
||||||
I had a dream about this site last night
|
|
||||||
</h1>""")
|
|
||||||
|
|
||||||
assert_that(censor_slurs("<p>retard Manlet NIG</p>", None)).is_equal_to("<p>r-slur Little king π</p>")
|
assert_that(censor_slurs("<p>retard Manlet NIG</p>", None)).is_equal_to("<p>r-slur Little king π</p>")
|
||||||
|
|
||||||
|
|
Loadingβ¦
Reference in New Issue