Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when posting code to comments #2343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion templates/comments/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h3>{{ _('New comment') }}</h3>
{{ _('You must solve at least one problem before your voice can be heard.') }}
</div>
{% else %}
<form class="comment-submit-form" action="" method="post">
<form class="comment-submit-form{% if comment_warn_code %} comment-warn-code{% endif %}" action="" method="post">
{% csrf_token %}
{% if comment_form.errors %}
<div id="form-errors">
Expand Down
10 changes: 10 additions & 0 deletions templates/comments/media-js.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@
$comment.find('.comment-body').show();
$comment.find('.bad-comment-body').hide();
};

var code_regex = [/input\(/, /#include/, /void\s+main/, /fn\s+main/, /func\s+main/];
$(document).on('click', 'form.comment-warn-code .button[type=submit]', function (e) {
var text = $(this).parents('form').find('#id_body').val();
if (code_regex.some(function (regex) {return regex.test(text);})) {
if (!confirm({{ _('Looks like you\'re trying to post some source code!\n\nThe comment section is not for posting source code.\nIf you want to submit your solution, please use the "Submit solution" button.\n\nAre you sure you want to post this?')|htmltojs }})) {
e.preventDefault();
}
}
});
});
</script>
{% endcompress %}
4 changes: 3 additions & 1 deletion templates/problem/problem.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ <h2><i class="fa fa-question-circle"></i> {{ _('Clarifications') }}</h2>
{% endif %}
</div>
{% elif enable_comments %}
{% include "comments/list.html" %}
{% with comment_warn_code=true %}
{% include "comments/list.html" %}
{% endwith %}
{% endif %}
{% endblock %}

Expand Down