From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.87]) by gnuweeb.org (Postfix) with ESMTPSA id C06AD81122; Tue, 18 Oct 2022 08:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1666081061; bh=SwL4iqnZ9qlwSVTGA6tMSqFXMuuSBDErDZvjHwkftiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1lnGC6r0fJ8fq0255COfgU4dq/smdj6KygHuB5wKL7HoByxH5B5MHV4o0lhlbeQL Kj6oNfsEA+NP2/0u5uP+b11Un2ilAVt88uXU9iZahSMQz99rkAllGHC7gET8fJELFR OUsoiiKNqrlo4hGalLeZyuf6uGMC72k07GiGFO3UYeSvd2EiHfXDKthEAeG3aBi9s2 LB6QVc9qP/TmTXeJSNYlBagrmdG0nPky68E1A0P+EGuJaXvBrQvI21/SsAjrfDXyw5 RtQJmA+nFrX5ItyTmMeu0jGa5STWuVoDgP1DeYYLpnejUtnzoyghiLiqtyH+3PsElv v/e6LXZPpQ4YA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 4/7] atom: Improve fix_utf8_char() Date: Tue, 18 Oct 2022 15:16:32 +0700 Message-Id: <20221018081635.1617-5-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221018081635.1617-1-kiizuha@gnuweeb.org> References: <20221018081635.1617-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: Improvement on the fix_utf8_char() and change the logic at the create_template(). Use the `platform == "discord"` to clean html escape. Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index a30d5cb..48857a7 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -206,7 +206,7 @@ def create_template(thread: Message, platform: str, to=None, cc=None): if len(ret) >= substr: ret = ret[:substr] + "..." - ret = fix_utf8_char(ret, platform == "telegram") + ret = fix_utf8_char(ret, platform == "discord") ret += border return ret, files, is_patch @@ -242,10 +242,12 @@ def remove_patch(tmp): shutil.rmtree(tmp) -def fix_utf8_char(text: str, html_escape: bool = True): +def fix_utf8_char(text: str, unescape: bool = True): t = text.rstrip().replace("�"," ") - if html_escape: - t = html.escape(html.escape(text)) + if unescape: + t = html.unescape(html.unescape(text)) + reg = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});') + t = reg.sub('', t) return t -- Muhammad Rizki