Commit 5ea90016 authored by Jonne Haß's avatar Jonne Haß

Merge pull request #5783 from visualsayed/5737-too-long-tag-name

5737 too long tag name
parents 6b217c32 18a1958e
......@@ -152,6 +152,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Fix mobile sign up from an invitation [#5754](https://github.com/diaspora/diaspora/pull/5754)
* Set max-width for tag following button on tag page [#5752](https://github.com/diaspora/diaspora/pull/5752)
* Display error messages for failed password change [#5580](https://github.com/diaspora/diaspora/pull/5580)
* Display correct error message for too long tags [#5783](https://github.com/diaspora/diaspora/pull/5783)
## Features
* Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105)
......
......@@ -93,7 +93,8 @@ class StatusMessagesController < ApplicationController
respond_to do |format|
format.html { redirect_to :back }
format.mobile { redirect_to stream_path }
format.json { render :text => @status_message.errors.messages[:text].to_sentence, :status => 403 }
#there are some errors, so we report the first one to the user
format.json { render :text => @status_message.errors.messages.values.first.to_sentence, :status => 403 }
end
end
end
......
......@@ -42,6 +42,7 @@ class Profile < ActiveRecord::Base
belongs_to :person
before_validation do
self.tag_string = self.tag_string.split[0..4].join(' ')
self.build_tags
end
before_save do
......
......@@ -1253,6 +1253,8 @@ en:
following: "Following #%{tag}"
stop_following: "Stop following #%{tag}"
none: "The empty tag does not exist!"
name_too_long: "Please make your tag name fewer than %{count} characters. Right now it is %{current_length} characters"
tag_followings:
create:
success: "Hooray! You’re now following #%{name}."
......
......@@ -7,9 +7,20 @@ module Diaspora
def self.included(model)
model.class_eval do
cattr_accessor :field_with_tags
# validate tag's name maximum length [tag's name should be less than or equal to 255 chars]
validate :tag_name_max_length, on: :create
# tag's name is limited to 255 charchters according to ActsAsTaggableOn gem, so we check the length of the name for each tag
def tag_name_max_length
self.tag_list.each do |tag|
errors[:tags] << I18n.t('tags.name_too_long', :count => 255, :current_length => tag.length) if tag.length > 255
end
end
protected :tag_name_max_length
end
model.instance_eval do
before_create :build_tags
before_validation :build_tags # build tags before validation fixs the too long tag name issue #5737
def extract_tags_from sym
self.field_with_tags = sym
......
......@@ -272,6 +272,11 @@ describe Profile, :type => :model do
@object.save
expect(@object.tags.count).to eq(5)
end
it 'should require tag name not be more than 255 characters long' do
@object.tag_string = "##{'a' * (255+1)}"
@object.save
expect(@object).not_to be_valid
end
it_should_behave_like 'it is taggable'
end
......
......@@ -70,6 +70,14 @@ describe StatusMessage, :type => :model do
expect(guids).to eq([sm1.guid])
end
end
describe '.before_validation' do
it 'calls build_tags' do
status = FactoryGirl.build(:status_message)
expect(status).to receive(:build_tags)
status.save
end
end
describe '.before_create' do
it 'calls build_tags' do
......@@ -255,6 +263,12 @@ STR
expect(msg_uc.tags).to match_array(tag_array)
expect(msg_cp.tags).to match_array(tag_array)
end
it 'should require tag name not be more than 255 characters long' do
message = "##{'a' * (255+1)}"
status_message = FactoryGirl.build(:status_message, :text => message)
expect(status_message).not_to be_valid
end
end
describe "XML" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment