about summary refs log tree commit diff
path: root/app/assets
diff options
context:
space:
mode:
authorAsh Furrow <ash@ashfurrow.com>2017-04-25 17:37:51 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-04-25 17:37:51 +0200
commit48652cb41e328e6ad32cb5cb54aefc978df6b11b (patch)
tree08b55e791389687506819800bbb972e7e9134cc6 /app/assets
parentd4f7f11c3c8f4c117394feccca9bbe537f59524d (diff)
Fixes string length issue for multibyte characters. (#2443)
Diffstat (limited to 'app/assets')
-rw-r--r--app/assets/javascripts/components/features/compose/components/character_counter.jsx3
-rw-r--r--app/assets/javascripts/extras.jsx7
2 files changed, 6 insertions, 4 deletions
diff --git a/app/assets/javascripts/components/features/compose/components/character_counter.jsx b/app/assets/javascripts/components/features/compose/components/character_counter.jsx
index 31d82d4d2..284c51b6d 100644
--- a/app/assets/javascripts/components/features/compose/components/character_counter.jsx
+++ b/app/assets/javascripts/components/features/compose/components/character_counter.jsx
@@ -1,4 +1,5 @@
 import PropTypes from 'prop-types';
+import { length } from 'stringz';
 
 class CharacterCounter extends React.PureComponent {
 
@@ -10,7 +11,7 @@ class CharacterCounter extends React.PureComponent {
   }
 
   render () {
-    const diff = this.props.max - this.props.text.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "_").length;
+    const diff = this.props.max - length(this.props.text);
 
     return this.checkRemainingText(diff);
   }
diff --git a/app/assets/javascripts/extras.jsx b/app/assets/javascripts/extras.jsx
index 29c37b9e1..7e3b7a256 100644
--- a/app/assets/javascripts/extras.jsx
+++ b/app/assets/javascripts/extras.jsx
@@ -1,4 +1,5 @@
-import emojify from './components/emoji'
+import emojify from './components/emoji';
+import { length } from 'stringz';
 
 $(() => {
   $.each($('.emojify'), (_, content) => {
@@ -40,9 +41,9 @@ $(() => {
 
   // used on /settings/profile
   $('.account_display_name').on('input', e => {
-    $('.name-counter').text(30 - $(e.target).val().length)
+    $('.name-counter').text(30 - length($(e.target).val()));
   });
   $('.account_note').on('input', e => {
-    $('.note-counter').text(160 - $(e.target).val().length)
+    $('.note-counter').text(160 - length($(e.target).val()));
   });
 });