Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Unify filter regular expression, disallow spaces, add optional word.
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltrout committed Jan 20, 2015
1 parent d654064 commit 3493cb4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions assets/javascripts/discourse/components/tag-chooser.js.es6
Expand Up @@ -26,7 +26,9 @@ export default Ember.TextField.extend({
}.observes('value'),

_initializeTags: function() {
var site = this.site;
var site = this.site,
filterRegexp = new RegExp(this.site.tags_filter_regexp, "g");

this.$().select2({
tags: true,
placeholder: I18n.t('tagging.choose_for_topic'),
Expand All @@ -53,7 +55,7 @@ export default Ember.TextField.extend({
callback(data);
},
createSearchChoice: function(term, data) {
term = term.replace(/[<\\\/\>\.\#\?\&]/g, '').trim();
term = term.replace(filterRegexp, '').trim();

// No empty terms, make sure the user has permission to create the tag
if (!term.length || !site.get('can_create_tag')) { return; }
Expand Down
2 changes: 1 addition & 1 deletion config/locales/client.en.yml
Expand Up @@ -20,5 +20,5 @@ en:
tagging:
all_tags: "All Tags"
tags: "Tags"
choose_for_topic: "choose tags for this topic"
choose_for_topic: "choose tags for this topic (optional)"
topics_tagged: "Topics tagged <span class='discourse-tag'>{{tag}}</span>"
4 changes: 3 additions & 1 deletion plugin.rb
Expand Up @@ -5,6 +5,7 @@

after_initialize do
TAGS_FIELD_NAME = "tags"
TAGS_FILTER_REGEXP = /[<\\\/\>\.\#\?\&\s]/

module ::DiscourseTagging
class Engine < ::Rails::Engine
Expand Down Expand Up @@ -85,7 +86,7 @@ def self.tags_by_count(limit=nil)

if params['tags'].present?
tags = params['tags']
tags.map! {|t| t.downcase.strip[0...SiteSetting.max_tag_length].gsub(/[<\\\/\>\.\#\?\&]/, '') }
tags.map! {|t| t.downcase.strip[0...SiteSetting.max_tag_length].gsub(TAGS_FILTER_REGEXP, '') }
tags.delete_if {|t| t.blank? }
tags.uniq!

Expand All @@ -112,6 +113,7 @@ def self.tags_by_count(limit=nil)
end

add_to_serializer(:site, :can_create_tag) { scope.can_create_tag? }
add_to_serializer(:site, :tags_filter_regexp) { TAGS_FILTER_REGEXP.source }

module AddCanCreateTagToGuardian
def can_create_tag?
Expand Down

0 comments on commit 3493cb4

Please sign in to comment.