<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import frappe
import re
from frappe.website.utils import clear_cache
from frappe.rate_limiter import rate_limit
from frappe.utils import add_to_date, now
from frappe.website.doctype.blog_settings.blog_settings import get_comment_limit

from frappe import _

@frappe.whitelist(allow_guest=True)
@rate_limit(key='reference_name', limit=get_comment_limit, seconds=60*60)
def add_comment(comment, comment_email, comment_by, reference_doctype, reference_name, route):
	doc = frappe.get_doc(reference_doctype, reference_name)

	if frappe.session.user == 'Guest' and doc.doctype not in ['Blog Post', 'Web Page']:
		return

	if not comment.strip():
		frappe.msgprint(_('The comment cannot be empty'))
		return False

	url_regex = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", re.IGNORECASE)
	email_regex = re.compile(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", re.IGNORECASE)

	if url_regex.search(comment) or email_regex.search(comment):
		frappe.msgprint(_('Comments cannot have links or email addresses'))
		return False

	comment = doc.add_comment(
		text=comment,
		comment_email=comment_email,
		comment_by=comment_by)

	comment.db_set('published', 1)

	# since comments are embedded in the page, clear the web cache
	if route:
		clear_cache(route)

	content = (comment.content
		+ "<p><a href='{0}/app/Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
			comment.name,
			_("View Comment")))<commit_msg>fix: filter html tags in comments<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: MIT. See LICENSE
import frappe
import re
from frappe.website.utils import clear_cache
from frappe.rate_limiter import rate_limit
from frappe.utils import add_to_date, now
from frappe.website.doctype.blog_settings.blog_settings import get_comment_limit
from frappe.utils.html_utils import clean_html

from frappe import _

@frappe.whitelist(allow_guest=True)
@rate_limit(key='reference_name', limit=get_comment_limit, seconds=60*60)
def add_comment(comment, comment_email, comment_by, reference_doctype, reference_name, route):
	doc = frappe.get_doc(reference_doctype, reference_name)

	if frappe.session.user == 'Guest' and doc.doctype not in ['Blog Post', 'Web Page']:
		return

	if not comment.strip():
		frappe.msgprint(_('The comment cannot be empty'))
		return False

	url_regex = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", re.IGNORECASE)
	email_regex = re.compile(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", re.IGNORECASE)

	if url_regex.search(comment) or email_regex.search(comment):
		frappe.msgprint(_('Comments cannot have links or email addresses'))
		return False

	comment = doc.add_comment(
		text=clean_html(comment),
		comment_email=comment_email,
		comment_by=comment_by)

	comment.db_set('published', 1)

	# since comments are embedded in the page, clear the web cache
	if route:
		clear_cache(route)

	content = (comment.content
		+ "<p><a href='{0}/app/Form/Comment/{1}' style='font-size: 80%'>{2}</a></p>".format(frappe.utils.get_request_site_address(),
			comment.name,
			_("View Comment")))
{'fraction_non_alphanumeric': 0.15830579753679783, 'fraction_numerical': 0.015620306398317813, 'mean_word_length': 5.529411764705882, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '125738', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1227, 'n_words': 258}