From 602ec1ccaf53c8f0a0532f55626e010cb9557725 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Tue, 22 Oct 2019 13:12:53 +1100 Subject: [PATCH] Also block displayname characters in the edit display name menu and change spaces to underscores --- _locales/en/messages.json | 3 ++- background.html | 2 +- js/views/nickname_dialog_view.js | 16 ++++++++++++++++ js/views/standalone_registration_view.js | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e58951412..5c820e9e9 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1899,7 +1899,8 @@ "Shown in the settings page as the heading for the blocked user settings" }, "editProfileTitle": { - "message": "Change your own display name", + "message": + "Change your own display name (alphanumeric characters and underscores only)", "description": "The title shown when user edits their own profile" }, "editProfileDisplayNameWarning": { diff --git a/background.html b/background.html index acad1030c..b164ad5fa 100644 --- a/background.html +++ b/background.html @@ -622,7 +622,7 @@
-
Enter your public display name (alphanumeric characters and spaces only)
+
Enter your public display name (alphanumeric characters and underscores only)
diff --git a/js/views/nickname_dialog_view.js b/js/views/nickname_dialog_view.js index 2414de0d4..ba65ff4de 100644 --- a/js/views/nickname_dialog_view.js +++ b/js/views/nickname_dialog_view.js @@ -31,6 +31,22 @@ this.$input.focus(); this.validateNickname(); + + const sanitiseNameInput = () => { + const oldVal = this.$input.val(); + this.$input.val(oldVal.replace(/[^a-zA-Z0-9_]/g, '')); + }; + + this.$input[0].oninput = () => { + sanitiseNameInput(); + }; + + this.$input[0].onpaste = () => { + // Sanitise data immediately after paste because it's easier + setTimeout(() => { + sanitiseNameInput(); + }); + }; }, events: { keyup: 'onKeyup', diff --git a/js/views/standalone_registration_view.js b/js/views/standalone_registration_view.js index edf799850..46036eac4 100644 --- a/js/views/standalone_registration_view.js +++ b/js/views/standalone_registration_view.js @@ -59,7 +59,7 @@ const sanitiseNameInput = () => { const oldVal = this.$('#display-name').val(); - this.$('#display-name').val(oldVal.replace(/[^a-zA-Z0-9 ]/g, '')); + this.$('#display-name').val(oldVal.replace(/[^a-zA-Z0-9_]/g, '')); }; this.$('#display-name').get(0).oninput = () => {