From c5f9ae0de1a7c871f3ccfac69886cc7cf8d375aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr> Date: Thu, 7 Jan 2016 22:23:01 +0100 Subject: [PATCH] FIX: username mentions weren't working when immediately followed by a dot --- .../discourse/dialects/category_hashtag_dialect.js | 2 +- .../javascripts/discourse/dialects/mention_dialect.js | 4 ++-- app/models/username_validator.rb | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/dialects/category_hashtag_dialect.js b/app/assets/javascripts/discourse/dialects/category_hashtag_dialect.js index 1ea3052b8..4beb7ab53 100644 --- a/app/assets/javascripts/discourse/dialects/category_hashtag_dialect.js +++ b/app/assets/javascripts/discourse/dialects/category_hashtag_dialect.js @@ -4,7 +4,7 @@ **/ Discourse.Dialect.inlineRegexp({ start: '#', - matcher: /^#([\w-]{1,50})/, + matcher: /^#([\w-]{1,50})/i, spaceOrTagBoundary: true, emitter: function(matches) { diff --git a/app/assets/javascripts/discourse/dialects/mention_dialect.js b/app/assets/javascripts/discourse/dialects/mention_dialect.js index 1641c3094..3848ae150 100644 --- a/app/assets/javascripts/discourse/dialects/mention_dialect.js +++ b/app/assets/javascripts/discourse/dialects/mention_dialect.js @@ -7,11 +7,11 @@ Discourse.Dialect.inlineRegexp({ start: '@', // NOTE: since we can't use SiteSettings here (they loads later in process) // we are being less strict to account for more cases than allowed - matcher: /^@([\w.-]+)/, + matcher: /^@(\w[\w.-]{0,59})\b/i, wordBoundary: true, emitter: function(matches) { - var mention = matches[0], + var mention = matches[0].trim(), name = matches[1], mentionLookup = this.dialect.options.mentionLookup; diff --git a/app/models/username_validator.rb b/app/models/username_validator.rb index 891958b16..e0ba6cfac 100644 --- a/app/models/username_validator.rb +++ b/app/models/username_validator.rb @@ -61,21 +61,21 @@ class UsernameValidator def username_char_valid? return unless errors.empty? - if username =~ /[^A-Za-z0-9_\.\-]/ + if username =~ /[^\w.-]/ self.errors << I18n.t(:'user.username.characters') end end def username_first_char_valid? return unless errors.empty? - if username[0] =~ /[^A-Za-z0-9_]/ + if username[0] =~ /[^\w]/ self.errors << I18n.t(:'user.username.must_begin_with_alphanumeric') end end def username_last_char_valid? return unless errors.empty? - if username[-1] =~ /[^A-Za-z0-9_]/ + if username[-1] =~ /[^\w]/ self.errors << I18n.t(:'user.username.must_end_with_alphanumeric') end end