From b345cedf2a3b247b712c754d082d08775c2c7f53 Mon Sep 17 00:00:00 2001 From: Yo Mama Date: Sat, 16 Oct 2021 20:56:12 +0200 Subject: [PATCH] Fixed not passing the logged user to the censor --- files/classes/comment.py | 4 +-- files/classes/submission.py | 4 +-- files/helpers/word_censor.py | 4 +-- test/files/helpers/test_word_censor.py | 40 +++++++++++++------------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 4d6e74406..eb7e6a453 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -300,7 +300,7 @@ class Comment(Base): if not body: return "" - body = censor_slurs(body) + body = censor_slurs(body, v) if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") @@ -326,7 +326,7 @@ class Comment(Base): if not body: return "" - body = censor_slurs(body) + body = censor_slurs(body, v) if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") diff --git a/files/classes/submission.py b/files/classes/submission.py index 63ace1e42..61e0ca93a 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -342,7 +342,7 @@ class Submission(Base): if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY" body = self.body_html - body = censor_slurs(body) + body = censor_slurs(body, v) if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") @@ -352,7 +352,7 @@ class Submission(Base): if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY" body = self.body - body = censor_slurs(body) + body = censor_slurs(body, v) if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") diff --git a/files/helpers/word_censor.py b/files/helpers/word_censor.py index 544aee775..a1e8ab788 100644 --- a/files/helpers/word_censor.py +++ b/files/helpers/word_censor.py @@ -47,8 +47,8 @@ def sub_matcher(match: Match): return (match.group(1) or '') + replacer + (match.group(4) or '') -def censor_slurs(v, body: str): - if v and not v.slurreplacer: +def censor_slurs(body: str, logged_user): + if logged_user and not logged_user.slurreplacer: return body for (slur, replace) in SLURS.items(): diff --git a/test/files/helpers/test_word_censor.py b/test/files/helpers/test_word_censor.py index 5ffba82ce..af89081b7 100644 --- a/test/files/helpers/test_word_censor.py +++ b/test/files/helpers/test_word_censor.py @@ -83,25 +83,25 @@ def test_sub_matcher(): def test_censor_slurs(): word_censor.REPLACE_MAP = create_replace_map() - assert_that(censor_slurs(None, "

retard

")).is_equal_to("

r-slur

") - assert_that(censor_slurs(None, "

preretard

")).is_equal_to("

prer-slur

") - assert_that(censor_slurs(None, "that is Retarded like")).is_equal_to("that is R-slured like") - assert_that(censor_slurs(None, "that is SUPERRETARD like")).is_equal_to("that is SUPERR-SLUR like") - assert_that(censor_slurs(None, "

Manlets get out!

")).is_equal_to("

Little kings get out!

") + assert_that(censor_slurs("

retard

", None)).is_equal_to("

r-slur

") + assert_that(censor_slurs("

preretard

", None)).is_equal_to("

prer-slur

") + assert_that(censor_slurs("that is Retarded like", None)).is_equal_to("that is R-slured like") + assert_that(censor_slurs("that is SUPERRETARD like", None)).is_equal_to("that is SUPERR-SLUR like") + assert_that(censor_slurs("

Manlets get out!

", None)).is_equal_to("

Little kings get out!

") - assert_that(censor_slurs(None, '... "retard" ...')).is_equal_to('... "retard" ...') - assert_that(censor_slurs(None, '... ReTaRd ...')).is_equal_to('... ReTaRd ...') - assert_that(censor_slurs(None, '... xretardx ...')).is_equal_to('... xretardx ...') + assert_that(censor_slurs('... "retard" ...', None)).is_equal_to('... "retard" ...') + assert_that(censor_slurs('... ReTaRd ...', None)).is_equal_to('... ReTaRd ...') + assert_that(censor_slurs('... xretardx ...', None)).is_equal_to('... xretardx ...') - assert_that(censor_slurs(None, "LLM is a manlet hehe")).is_equal_to("LLM is a little king hehe") - assert_that(censor_slurs(None, "LLM is :marseycapitalistmanlet: hehe")) \ + assert_that(censor_slurs("LLM is a manlet hehe", None)).is_equal_to("LLM is a little king hehe") + assert_that(censor_slurs("LLM is :marseycapitalistmanlet: hehe", None)) \ .is_equal_to("LLM is :marseycapitalistmanlet: hehe") - assert_that(censor_slurs(None, '... Nig ...')).is_equal_to('... 🏀 ...') - assert_that(censor_slurs(None, '

NIG

')).is_equal_to('

🏀

') - assert_that(censor_slurs(None, '... nigeria ...')).is_equal_to('... nigeria ...') + assert_that(censor_slurs('... Nig ...', None)).is_equal_to('... 🏀 ...') + assert_that(censor_slurs('

NIG

', None)).is_equal_to('

🏀

') + assert_that(censor_slurs('... nigeria ...', None)).is_equal_to('... nigeria ...') - assert_that(censor_slurs(None, "

retarded SuperManlet NIG

")) \ + assert_that(censor_slurs("

retarded SuperManlet NIG

", None)) \ .is_equal_to("

r-slured SuperLittle king 🏀

") @@ -110,19 +110,19 @@ def test_censor_slurs_does_not_error_out_on_exception(): word_censor.REPLACE_MAP = create_replace_map() word_censor.REPLACE_MAP["Manlet"] = None - assert_that(censor_slurs(None, ">retarded SuperManlet NIG<")).is_equal_to(">r-slured SuperManlet 🏀<") + assert_that(censor_slurs(">retarded SuperManlet NIG<", None)).is_equal_to(">r-slured SuperManlet 🏀<") @patch("files.helpers.word_censor.SLURS", {'retard': 'r-slur', 'manlet': 'little king'}) def test_censor_slurs_does_not_censor_on_flag_disabled(): word_censor.REPLACE_MAP = create_replace_map() - class V: + class User: def __init__(self, slurreplacer): self.slurreplacer = slurreplacer - v = V(False) - assert_that(censor_slurs(v, "

retard

")).is_equal_to("

retard

") + logger_user = User(slurreplacer=False) + assert_that(censor_slurs("

retard

", logger_user)).is_equal_to("

retard

") - v = V(True) - assert_that(censor_slurs(v, "

retard

")).is_equal_to("

r-slur

") + logger_user = User(slurreplacer=True) + assert_that(censor_slurs("

retard

", logger_user)).is_equal_to("

r-slur

")