streams_edit: Prevent newline characters in the description.

This commit achieves two things:
  1. Changes the UI of the "Create stream" form to make the
     textarea previously used to get the stream description
     a simple input field of type text (to suggest a single
     line description).

  2. Adds an extra check on the frontend side to make sure that
     when users create a new stream via. the "Create stream"
     option in the settings panel, they can't enter any newline
     characters (i.e. we disallow the enter key from being
     registered when typing out the stream description).
     We must also make sure that they cannot copy-and-paste over
     descriptions containing newline characters.

  resolves #11617
This commit is contained in:
Hemanth V. Alluri 2019-02-20 23:06:46 +05:30 committed by Tim Abbott
parent 95d04386e2
commit 3134453220
2 changed files with 18 additions and 2 deletions

View File

@ -195,6 +195,14 @@ function create_stream() {
var announce = !!page_params.notifications_stream &&
$('#announce-new-stream input').prop('checked');
// Even though we already check to make sure that while typing the user cannot enter
// newline characters (by pressing the enter key) it would still be possible to copy
// and paste over a description with newline characters in it. Prevent that.
if (description.indexOf('\n') !== -1) {
ui_report.message(i18n.t("The stream description cannot contain newline characters."), $(".stream_create_info"), 'alert-error');
return;
}
loading.make_indicator($('#stream_creating_indicator'), {text: i18n.t('Creating stream...')});
ajaxSubscribeForCreation(
@ -437,6 +445,14 @@ exports.set_up_handlers = function () {
e.stopPropagation();
});
// Do not allow the user to enter newline characters while typing out the
// stream's description during it's creation.
container.on("keydown", "#create_stream_description", function (e) {
if ((e.keyCode || e.which) === 13) {
e.preventDefault();
}
});
};
return exports;

View File

@ -16,8 +16,8 @@
<div class="stream-title">
{{t "Stream description (optional)"}}
</div>
<textarea name="stream_description" id="create_stream_description"
placeholder="{{t 'Stream description' }}" value="" autocomplete="off" maxlength="{{ max_description_length }}"></textarea>
<input type="text" name="stream_description" id="create_stream_description"
placeholder="{{t 'Stream description' }}" value="" autocomplete="off" maxlength="{{ max_description_length }}" />
</section>
<section class="block" id="make-invite-only">
<div class="stream-title">