mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Temporary Nuclear option on topic titles - disallow non ascii characters so we
can stay on top of the trolls. This is meant to be replaced soon with a more permissive and safe method of sanitizing.
This commit is contained in:
parent
f1a3e76d2b
commit
2d2b907d2c
3 changed files with 31 additions and 0 deletions
|
@ -24,6 +24,7 @@ class Topic < ActiveRecord::Base
|
||||||
serialize :meta_data, ActiveRecord::Coders::Hstore
|
serialize :meta_data, ActiveRecord::Coders::Hstore
|
||||||
|
|
||||||
validate :unique_title
|
validate :unique_title
|
||||||
|
validate :nuclear_option
|
||||||
|
|
||||||
belongs_to :category
|
belongs_to :category
|
||||||
has_many :posts
|
has_many :posts
|
||||||
|
@ -112,6 +113,21 @@ class Topic < ActiveRecord::Base
|
||||||
errors.add(:title, I18n.t(:has_already_been_used)) if finder.exists?
|
errors.add(:title, I18n.t(:has_already_been_used)) if finder.exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This is bad, but people are screwing us on try.discourse.org - soon we'll replace with
|
||||||
|
# a much more sane validation of odd characters to allow for other languages and such.
|
||||||
|
def nuclear_option
|
||||||
|
|
||||||
|
# Let presence validation catch it if it's blank
|
||||||
|
return if title.blank?
|
||||||
|
|
||||||
|
title.each_char do |c|
|
||||||
|
unless (20..126).include?(c.ord)
|
||||||
|
errors.add(:title, I18n.t(:invalid_characters))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def new_version_required?
|
def new_version_required?
|
||||||
return true if title_changed?
|
return true if title_changed?
|
||||||
|
|
|
@ -8,6 +8,7 @@ en:
|
||||||
too_many_links: "has too many links"
|
too_many_links: "has too many links"
|
||||||
just_posted_that: "is too similar to what you recently posted"
|
just_posted_that: "is too similar to what you recently posted"
|
||||||
has_already_been_used: "has already been used"
|
has_already_been_used: "has already been used"
|
||||||
|
invalid_characters: "contains invalid characters"
|
||||||
|
|
||||||
activerecord:
|
activerecord:
|
||||||
attributes:
|
attributes:
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Topic do
|
describe Topic do
|
||||||
|
@ -24,6 +26,18 @@ describe Topic do
|
||||||
|
|
||||||
it { should rate_limit }
|
it { should rate_limit }
|
||||||
|
|
||||||
|
context 'topic title content' do
|
||||||
|
|
||||||
|
it "allows a regular title with a few ascii characters" do
|
||||||
|
Fabricate.build(:topic, title: "hello this is my cool topic! welcome: all;").should be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't allow non standard ascii" do
|
||||||
|
Fabricate.build(:topic, title: "Iñtërnâtiônàlizætiøn").should_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'topic title uniqueness' do
|
context 'topic title uniqueness' do
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue