]> git.openstreetmap.org Git - rails.git/commitdiff
Create invalid_char validators and apply to models
authorJ Guthrie <jamie.guthrie@gmail.com>
Sun, 4 Nov 2018 18:28:27 +0000 (18:28 +0000)
committerJ Guthrie <jamie.guthrie@gmail.com>
Mon, 5 Nov 2018 14:27:03 +0000 (14:27 +0000)
25 files changed:
app/models/changeset_comment.rb
app/models/changeset_tag.rb
app/models/diary_comment.rb
app/models/diary_entry.rb
app/models/issue_comment.rb
app/models/message.rb
app/models/node_tag.rb
app/models/note_comment.rb
app/models/old_node_tag.rb
app/models/old_relation_tag.rb
app/models/old_way_tag.rb
app/models/redaction.rb
app/models/relation_tag.rb
app/models/report.rb
app/models/trace.rb
app/models/tracetag.rb
app/models/user.rb
app/models/user_block.rb
app/models/user_preference.rb
app/models/way_tag.rb
app/validators/invalid_chars_validator.rb [new file with mode: 0644]
app/validators/invalid_url_chars_validator.rb [new file with mode: 0644]
app/validators/leading_whitespace_validator.rb [new file with mode: 0644]
app/validators/trailing_whitespace_validator.rb [new file with mode: 0644]
config/locales/en.yml

index 756fda14c6e7b85adb198d89ddf002316ce9d740..232785d95de585f6d2d508bf7381f31a0adfbb4f 100644 (file)
@@ -3,8 +3,8 @@
 # Table name: changeset_comments
 #
 #  id           :integer          not null, primary key
 # Table name: changeset_comments
 #
 #  id           :integer          not null, primary key
-#  changeset_id :integer          not null
-#  author_id    :integer          not null
+#  changeset_id :bigint(8)        not null
+#  author_id    :bigint(8)        not null
 #  body         :text             not null
 #  created_at   :datetime         not null
 #  visible      :boolean          not null
 #  body         :text             not null
 #  created_at   :datetime         not null
 #  visible      :boolean          not null
@@ -28,7 +28,7 @@ class ChangesetComment < ActiveRecord::Base
   validates :changeset, :presence => true, :associated => true
   validates :author, :presence => true, :associated => true
   validates :visible, :inclusion => [true, false]
   validates :changeset, :presence => true, :associated => true
   validates :author, :presence => true, :associated => true
   validates :visible, :inclusion => [true, false]
-  validates :body, :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
+  validates :body, :invalid_chars => true
 
   # Return the comment text
   def body
 
   # Return the comment text
   def body
index 8d6cd45ac3bb1056aa72f8643b4dfd7c8c37ffe1..1231fc24f5c2367b9d63a39a84a642b604e79da9 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Table name: changeset_tags
 #
 #
 # Table name: changeset_tags
 #
-#  changeset_id :integer          not null, primary key
+#  changeset_id :bigint(8)        not null, primary key
 #  k            :string           default(""), not null, primary key
 #  v            :string           default(""), not null
 #
 #  k            :string           default(""), not null, primary key
 #  v            :string           default(""), not null
 #
@@ -21,6 +21,6 @@ class ChangesetTag < ActiveRecord::Base
   belongs_to :changeset
 
   validates :changeset, :presence => true, :associated => true
   belongs_to :changeset
 
   validates :changeset, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => :changeset_id }
 end
   validates :k, :uniqueness => { :scope => :changeset_id }
 end
index 63eae3f213ee621f7016459271e46af036661a77..472129b1b6e174c0a525ff70a648b9d78b8904f9 100644 (file)
@@ -2,9 +2,9 @@
 #
 # Table name: diary_comments
 #
 #
 # Table name: diary_comments
 #
-#  id             :integer          not null, primary key
-#  diary_entry_id :integer          not null
-#  user_id        :integer          not null
+#  id             :bigint(8)        not null, primary key
+#  diary_entry_id :bigint(8)        not null
+#  user_id        :bigint(8)        not null
 #  body           :text             not null
 #  created_at     :datetime         not null
 #  updated_at     :datetime         not null
 #  body           :text             not null
 #  created_at     :datetime         not null
 #  updated_at     :datetime         not null
@@ -28,7 +28,7 @@ class DiaryComment < ActiveRecord::Base
 
   scope :visible, -> { where(:visible => true) }
 
 
   scope :visible, -> { where(:visible => true) }
 
-  validates :body, :presence => true
+  validates :body, :presence => true, :invalid_chars => true
   validates :diary_entry, :user, :associated => true
 
   after_save :spam_check
   validates :diary_entry, :user, :associated => true
 
   after_save :spam_check
index 2a24d800296b80902fffdd33656e67447505e9a5..d4139f65228f4d1e4a01a4dca73b45808fffe1a4 100644 (file)
@@ -2,8 +2,8 @@
 #
 # Table name: diary_entries
 #
 #
 # Table name: diary_entries
 #
-#  id            :integer          not null, primary key
-#  user_id       :integer          not null
+#  id            :bigint(8)        not null, primary key
+#  user_id       :bigint(8)        not null
 #  title         :string           not null
 #  body          :text             not null
 #  created_at    :datetime         not null
 #  title         :string           not null
 #  body          :text             not null
 #  created_at    :datetime         not null
@@ -37,7 +37,7 @@ class DiaryEntry < ActiveRecord::Base
 
   scope :visible, -> { where(:visible => true) }
 
 
   scope :visible, -> { where(:visible => true) }
 
-  validates :title, :body, :presence => true
+  validates :title, :body, :presence => true, :invalid_chars => true
   validates :title, :length => 1..255
   validates :latitude, :allow_nil => true,
                        :numericality => { :greater_than_or_equal_to => -90,
   validates :title, :length => 1..255
   validates :latitude, :allow_nil => true,
                        :numericality => { :greater_than_or_equal_to => -90,
index 3a5894cb3e1b4cab5ee1a91ed077164ed2faf77f..2fe96f4728857271b031dc4579797b630196aacf 100644 (file)
@@ -24,7 +24,7 @@ class IssueComment < ActiveRecord::Base
   belongs_to :issue
   belongs_to :user
 
   belongs_to :issue
   belongs_to :user
 
-  validates :body, :presence => true
+  validates :body, :presence => true, :invalid_chars => true
   validates :user, :presence => true
   validates :issue, :presence => true
 end
   validates :user, :presence => true
   validates :issue, :presence => true
 end
index aff628e035901e685c18515902087db8e48a088d..2447c3b7940821da7380764bbdc70801484dd057 100644 (file)
@@ -2,13 +2,13 @@
 #
 # Table name: messages
 #
 #
 # Table name: messages
 #
-#  id                :integer          not null, primary key
-#  from_user_id      :integer          not null
+#  id                :bigint(8)        not null, primary key
+#  from_user_id      :bigint(8)        not null
 #  title             :string           not null
 #  body              :text             not null
 #  sent_on           :datetime         not null
 #  message_read      :boolean          default(FALSE), not null
 #  title             :string           not null
 #  body              :text             not null
 #  sent_on           :datetime         not null
 #  message_read      :boolean          default(FALSE), not null
-#  to_user_id        :integer          not null
+#  to_user_id        :bigint(8)        not null
 #  to_user_visible   :boolean          default(TRUE), not null
 #  from_user_visible :boolean          default(TRUE), not null
 #  body_format       :enum             default("markdown"), not null
 #  to_user_visible   :boolean          default(TRUE), not null
 #  from_user_visible :boolean          default(TRUE), not null
 #  body_format       :enum             default("markdown"), not null
@@ -32,6 +32,7 @@ class Message < ActiveRecord::Base
 
   validates :title, :presence => true, :utf8 => true, :length => 1..255
   validates :body, :sent_on, :sender, :recipient, :presence => true
 
   validates :title, :presence => true, :utf8 => true, :length => 1..255
   validates :body, :sent_on, :sender, :recipient, :presence => true
+  validates :title, :body, :invalid_chars => true
 
   def self.from_mail(mail, from, to)
     if mail.multipart?
 
   def self.from_mail(mail, from, to)
     if mail.multipart?
index 20065b993137f8e1df485c24c81d716371c062ae..d1e80059232980373c6b1c18daeb10db458e7a4d 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Table name: current_node_tags
 #
 #
 # Table name: current_node_tags
 #
-#  node_id :integer          not null, primary key
+#  node_id :bigint(8)        not null, primary key
 #  k       :string           default(""), not null, primary key
 #  v       :string           default(""), not null
 #
 #  k       :string           default(""), not null, primary key
 #  v       :string           default(""), not null
 #
@@ -18,6 +18,6 @@ class NodeTag < ActiveRecord::Base
   belongs_to :node
 
   validates :node, :presence => true, :associated => true
   belongs_to :node
 
   validates :node, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => :node_id }
 end
   validates :k, :uniqueness => { :scope => :node_id }
 end
index 1772b3f9728aaab6502dec45b0a0f15977c678d2..69a93c532a53354f725a0490d5d01461ac6a8b66 100644 (file)
@@ -34,7 +34,7 @@ class NoteComment < ActiveRecord::Base
   validates :author, :associated => true
   validates :event, :inclusion => %w[opened closed reopened commented hidden]
   validates :body, :length => { :maximum => 2000 },
   validates :author, :associated => true
   validates :event, :inclusion => %w[opened closed reopened commented hidden]
   validates :body, :length => { :maximum => 2000 },
-                   :format => /\A[^\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff]*\z/
+                   :invalid_chars => true
 
   # Return the comment text
   def body
 
   # Return the comment text
   def body
index 9e03d34f983a86553d6ca2fb3b8c7ff5d8472056..f6fb93e17b8ab77b63e98dabeaeab5123f00e7ab 100644 (file)
@@ -2,8 +2,8 @@
 #
 # Table name: node_tags
 #
 #
 # Table name: node_tags
 #
-#  node_id :integer          not null, primary key
-#  version :integer          not null, primary key
+#  node_id :bigint(8)        not null, primary key
+#  version :bigint(8)        not null, primary key
 #  k       :string           default(""), not null, primary key
 #  v       :string           default(""), not null
 #
 #  k       :string           default(""), not null, primary key
 #  v       :string           default(""), not null
 #
@@ -19,6 +19,6 @@ class OldNodeTag < ActiveRecord::Base
   belongs_to :old_node, :foreign_key => [:node_id, :version]
 
   validates :old_node, :presence => true, :associated => true
   belongs_to :old_node, :foreign_key => [:node_id, :version]
 
   validates :old_node, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => [:node_id, :version] }
 end
   validates :k, :uniqueness => { :scope => [:node_id, :version] }
 end
index 052b60853e9ec0f630d9b8ccd5aef59b81c89575..3b75e1c820cb37a2d0351c840fac70bc9a1bf7bc 100644 (file)
@@ -2,10 +2,10 @@
 #
 # Table name: relation_tags
 #
 #
 # Table name: relation_tags
 #
-#  relation_id :integer          default(0), not null, primary key
+#  relation_id :bigint(8)        default(0), not null, primary key
 #  k           :string           default(""), not null, primary key
 #  v           :string           default(""), not null
 #  k           :string           default(""), not null, primary key
 #  v           :string           default(""), not null
-#  version     :integer          not null, primary key
+#  version     :bigint(8)        not null, primary key
 #
 # Foreign Keys
 #
 #
 # Foreign Keys
 #
@@ -19,6 +19,6 @@ class OldRelationTag < ActiveRecord::Base
   belongs_to :old_relation, :foreign_key => [:relation_id, :version]
 
   validates :old_relation, :presence => true, :associated => true
   belongs_to :old_relation, :foreign_key => [:relation_id, :version]
 
   validates :old_relation, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => [:relation_id, :version] }
 end
   validates :k, :uniqueness => { :scope => [:relation_id, :version] }
 end
index 8fffebc2553ab9e8c217195dd8da41c56374f787..14043546cb38feff5f0406757ffd39ece9452435 100644 (file)
@@ -2,10 +2,10 @@
 #
 # Table name: way_tags
 #
 #
 # Table name: way_tags
 #
-#  way_id  :integer          default(0), not null, primary key
+#  way_id  :bigint(8)        default(0), not null, primary key
 #  k       :string           not null, primary key
 #  v       :string           not null
 #  k       :string           not null, primary key
 #  v       :string           not null
-#  version :integer          not null, primary key
+#  version :bigint(8)        not null, primary key
 #
 # Foreign Keys
 #
 #
 # Foreign Keys
 #
@@ -19,6 +19,6 @@ class OldWayTag < ActiveRecord::Base
   belongs_to :old_way, :foreign_key => [:way_id, :version]
 
   validates :old_way, :presence => true, :associated => true
   belongs_to :old_way, :foreign_key => [:way_id, :version]
 
   validates :old_way, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => [:way_id, :version] }
 end
   validates :k, :uniqueness => { :scope => [:way_id, :version] }
 end
index b835864db074b40e7c27cfd8521e0689b96aa979..d9a5c6cd793091fd893facd7b8130c1af2bc2473 100644 (file)
@@ -7,7 +7,7 @@
 #  description        :text
 #  created_at         :datetime
 #  updated_at         :datetime
 #  description        :text
 #  created_at         :datetime
 #  updated_at         :datetime
-#  user_id            :integer          not null
+#  user_id            :bigint(8)        not null
 #  description_format :enum             default("markdown"), not null
 #
 # Foreign Keys
 #  description_format :enum             default("markdown"), not null
 #
 # Foreign Keys
@@ -31,6 +31,7 @@ class Redaction < ActiveRecord::Base
   has_many :old_ways
   has_many :old_relations
 
   has_many :old_ways
   has_many :old_relations
 
+  validates :title, :description, :invalid_chars => true
   validates :description, :presence => true
   validates :description_format, :inclusion => { :in => %w[text html markdown] }
 
   validates :description, :presence => true
   validates :description_format, :inclusion => { :in => %w[text html markdown] }
 
index 5dc609987370ffbc3731e9f6864fc5b155f65f6a..02d5a216be67f29786a3a371e928a4ae6d11df1c 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Table name: current_relation_tags
 #
 #
 # Table name: current_relation_tags
 #
-#  relation_id :integer          not null, primary key
+#  relation_id :bigint(8)        not null, primary key
 #  k           :string           default(""), not null, primary key
 #  v           :string           default(""), not null
 #
 #  k           :string           default(""), not null, primary key
 #  v           :string           default(""), not null
 #
@@ -18,6 +18,6 @@ class RelationTag < ActiveRecord::Base
   belongs_to :relation
 
   validates :relation, :presence => true, :associated => true
   belongs_to :relation
 
   validates :relation, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => :relation_id }
 end
   validates :k, :uniqueness => { :scope => :relation_id }
 end
index 63296a0948b9aae2a3ff7d1ac93423d9cf080e25..ac00f1cfb502366c24d2044b22235f310636ffef 100644 (file)
@@ -27,7 +27,7 @@ class Report < ActiveRecord::Base
 
   validates :issue, :presence => true
   validates :user, :presence => true
 
   validates :issue, :presence => true
   validates :user, :presence => true
-  validates :details, :presence => true
+  validates :details, :presence => true, :invalid_chars => true
   validates :category, :presence => true
 
   def self.categories_for(reportable)
   validates :category, :presence => true
 
   def self.categories_for(reportable)
index 5096a81aafcb7e69e9b77d8d90b3fd9f933ec545..0e81805509aea9ad62a3abe88de54f557bdb0f47 100644 (file)
@@ -2,17 +2,18 @@
 #
 # Table name: gpx_files
 #
 #
 # Table name: gpx_files
 #
-#  id          :integer          not null, primary key
-#  user_id     :integer          not null
+#  id          :bigint(8)        not null, primary key
+#  user_id     :bigint(8)        not null
 #  visible     :boolean          default(TRUE), not null
 #  name        :string           default(""), not null
 #  visible     :boolean          default(TRUE), not null
 #  name        :string           default(""), not null
-#  size        :integer
+#  size        :bigint(8)
 #  latitude    :float
 #  longitude   :float
 #  timestamp   :datetime         not null
 #  description :string           default(""), not null
 #  inserted    :boolean          not null
 #  visibility  :enum             default("public"), not null
 #  latitude    :float
 #  longitude   :float
 #  timestamp   :datetime         not null
 #  description :string           default(""), not null
 #  inserted    :boolean          not null
 #  visibility  :enum             default("public"), not null
+#  length      :bigint(8)
 #
 # Indexes
 #
 #
 # Indexes
 #
@@ -39,6 +40,7 @@ class Trace < ActiveRecord::Base
 
   validates :user, :presence => true, :associated => true
   validates :name, :presence => true, :length => 1..255
 
   validates :user, :presence => true, :associated => true
   validates :name, :presence => true, :length => 1..255
+  validates :name, :description, :invalid_chars => true
   validates :description, :presence => { :on => :create }, :length => 1..255
   validates :timestamp, :presence => true
   validates :visibility, :inclusion => %w[private public trackable identifiable]
   validates :description, :presence => { :on => :create }, :length => 1..255
   validates :timestamp, :presence => true
   validates :visibility, :inclusion => %w[private public trackable identifiable]
index 1a4fbd39889195a4653fcc1ed9fec5be3d8e4126..cb7cf1145814ef7dd7a9fa400510fa76956cdb5c 100644 (file)
@@ -2,9 +2,9 @@
 #
 # Table name: gpx_file_tags
 #
 #
 # Table name: gpx_file_tags
 #
-#  gpx_id :integer          default(0), not null
+#  gpx_id :bigint(8)        default(0), not null
 #  tag    :string           not null
 #  tag    :string           not null
-#  id     :integer          not null, primary key
+#  id     :bigint(8)        not null, primary key
 #
 # Indexes
 #
 #
 # Indexes
 #
@@ -22,5 +22,5 @@ class Tracetag < ActiveRecord::Base
   belongs_to :trace, :foreign_key => "gpx_id"
 
   validates :trace, :associated => true
   belongs_to :trace, :foreign_key => "gpx_id"
 
   validates :trace, :associated => true
-  validates :tag, :length => 1..255, :format => %r{\A[^/;.,?]*\z}
+  validates :tag, :length => 1..255, :format => %r{\A[^/;.,?]*\z}, :invalid_chars => true
 end
 end
index 37351c6b26c79f08fa2a6fe7e7a99d736b5297d4..0b0d37326a2c8b6b0b9d31849492eb71fcf04825 100644 (file)
@@ -88,23 +88,16 @@ class User < ActiveRecord::Base
                     :default_url => "/assets/:class/:attachment/:style.png",
                     :styles => { :large => "100x100>", :small => "50x50>" }
 
                     :default_url => "/assets/:class/:attachment/:style.png",
                     :styles => { :large => "100x100>", :small => "50x50>" }
 
-  INVALID_ASCII_CHARS = "/;.,?%#".freeze
-  INVALID_NON_ASCII_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
-
   validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
                            :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
   validates :display_name, :if => proc { |u| u.display_name_changed? },
                            :uniqueness => { :case_sensitive => false }
   validates :display_name, :if => proc { |u| u.display_name_changed? },
   validates :display_name, :presence => true, :allow_nil => true, :length => 3..255,
                            :exclusion => %w[new terms save confirm confirm-email go_public reset-password forgot-password suspended]
   validates :display_name, :if => proc { |u| u.display_name_changed? },
                            :uniqueness => { :case_sensitive => false }
   validates :display_name, :if => proc { |u| u.display_name_changed? },
-                           :format => { :with => /\A[^#{INVALID_NON_ASCII_CHARS}]*\z/ }
-  validates :display_name, :if => proc { |u| u.display_name_changed? },
-                           :format => { :with => /\A[^#{INVALID_ASCII_CHARS}]*\z/,
-                                        :message => I18n.t("users.account.invalid chars", :invalid_chars => INVALID_ASCII_CHARS) }
-  validates :display_name, :if => proc { |u| u.display_name_changed? },
-                           :format => { :with => /\A\S/, :message => I18n.t("users.account.leading whitespace") }
-  validates :display_name, :if => proc { |u| u.display_name_changed? },
-                           :format => { :with => /\S\z/, :message => I18n.t("users.account.trailing whitespace") }
-  validates :email, :presence => true, :confirmation => true
+                           :invalid_chars => true,
+                           :invalid_url_chars => true,
+                           :leading_whitespace => true,
+                           :trailing_whitespace => true
+  validates :email, :presence => true, :confirmation => true, :invalid_chars => true
   validates :email, :if => proc { |u| u.email_changed? },
                     :uniqueness => { :case_sensitive => false }
   validates :pass_crypt, :confirmation => true, :length => 8..255
   validates :email, :if => proc { |u| u.email_changed? },
                     :uniqueness => { :case_sensitive => false }
   validates :pass_crypt, :confirmation => true, :length => 8..255
index 9f32862af52546bfbf4542599d38916af0ca76e8..f56f87b9de255408ed72fb0d0a7044103c9591d0 100644 (file)
@@ -3,12 +3,12 @@
 # Table name: user_blocks
 #
 #  id            :integer          not null, primary key
 # Table name: user_blocks
 #
 #  id            :integer          not null, primary key
-#  user_id       :integer          not null
-#  creator_id    :integer          not null
+#  user_id       :bigint(8)        not null
+#  creator_id    :bigint(8)        not null
 #  reason        :text             not null
 #  ends_at       :datetime         not null
 #  needs_view    :boolean          default(FALSE), not null
 #  reason        :text             not null
 #  ends_at       :datetime         not null
 #  needs_view    :boolean          default(FALSE), not null
-#  revoker_id    :integer
+#  revoker_id    :bigint(8)
 #  created_at    :datetime
 #  updated_at    :datetime
 #  reason_format :enum             default("markdown"), not null
 #  created_at    :datetime
 #  updated_at    :datetime
 #  reason_format :enum             default("markdown"), not null
@@ -26,6 +26,7 @@
 
 class UserBlock < ActiveRecord::Base
   validate :moderator_permissions
 
 class UserBlock < ActiveRecord::Base
   validate :moderator_permissions
+  validates :reason, :invalid_chars => true
 
   belongs_to :user, :class_name => "User", :foreign_key => :user_id
   belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
 
   belongs_to :user, :class_name => "User", :foreign_key => :user_id
   belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
index 69b0e9ddec9fc020787c76165f3323ec9cceccd7..781dd626a7c251cc98dcc56232f9c013bf5500ad 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Table name: user_preferences
 #
 #
 # Table name: user_preferences
 #
-#  user_id :integer          not null, primary key
+#  user_id :bigint(8)        not null, primary key
 #  k       :string           not null, primary key
 #  v       :string           not null
 #
 #  k       :string           not null, primary key
 #  v       :string           not null
 #
@@ -17,7 +17,7 @@ class UserPreference < ActiveRecord::Base
   belongs_to :user
 
   validates :user, :presence => true, :associated => true
   belongs_to :user
 
   validates :user, :presence => true, :associated => true
-  validates :k, :v, :length => 1..255
+  validates :k, :v, :length => 1..255, :invalid_chars => true
 
   # Turn this Node in to an XML Node without the <osm> wrapper.
   def to_xml_node
 
   # Turn this Node in to an XML Node without the <osm> wrapper.
   def to_xml_node
index 8ef75f38e21698b99bb24b63e2cce6d6f0def5e1..4e0f7ee2df933fb714646e01b54de1b0c4f38b50 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Table name: current_way_tags
 #
 #
 # Table name: current_way_tags
 #
-#  way_id :integer          not null, primary key
+#  way_id :bigint(8)        not null, primary key
 #  k      :string           default(""), not null, primary key
 #  v      :string           default(""), not null
 #
 #  k      :string           default(""), not null, primary key
 #  v      :string           default(""), not null
 #
@@ -18,6 +18,6 @@ class WayTag < ActiveRecord::Base
   belongs_to :way
 
   validates :way, :presence => true, :associated => true
   belongs_to :way
 
   validates :way, :presence => true, :associated => true
-  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }
+  validates :k, :v, :allow_blank => true, :length => { :maximum => 255 }, :invalid_chars => true
   validates :k, :uniqueness => { :scope => :way_id }
 end
   validates :k, :uniqueness => { :scope => :way_id }
 end
diff --git a/app/validators/invalid_chars_validator.rb b/app/validators/invalid_chars_validator.rb
new file mode 100644 (file)
index 0000000..c324fd3
--- /dev/null
@@ -0,0 +1,9 @@
+class InvalidCharsValidator < ActiveModel::EachValidator
+  INVALID_CHARS = "\x00-\x08\x0b-\x0c\x0e-\x1f\x7f\ufffe\uffff".freeze
+
+  def validate_each(record, attribute, value)
+    if value =~ /[#{INVALID_CHARS}]/
+      record.errors[attribute] << (options[:message] || "contains invalid chars")
+    end
+  end
+end
\ No newline at end of file
diff --git a/app/validators/invalid_url_chars_validator.rb b/app/validators/invalid_url_chars_validator.rb
new file mode 100644 (file)
index 0000000..77a2fc5
--- /dev/null
@@ -0,0 +1,9 @@
+class InvalidUrlCharsValidator < ActiveModel::EachValidator
+  INVALID_URL_CHARS = "/;.,?%#".freeze
+
+  def validate_each(record, attribute, value)
+    if value =~ /[#{INVALID_URL_CHARS}]/
+      record.errors[attribute] << (options[:message] || I18n.t("validations.invalid chars", :invalid_chars => INVALID_URL_CHARS))
+    end
+  end
+end
\ No newline at end of file
diff --git a/app/validators/leading_whitespace_validator.rb b/app/validators/leading_whitespace_validator.rb
new file mode 100644 (file)
index 0000000..fcefb0a
--- /dev/null
@@ -0,0 +1,7 @@
+class LeadingWhitespaceValidator < ActiveModel::EachValidator
+  def validate_each(record, attribute, value)
+    if value =~ /\A\s/
+      record.errors[attribute] << (options[:message] || I18n.t("validations.leading whitespace"))
+    end
+  end
+end
\ No newline at end of file
diff --git a/app/validators/trailing_whitespace_validator.rb b/app/validators/trailing_whitespace_validator.rb
new file mode 100644 (file)
index 0000000..bb34ef4
--- /dev/null
@@ -0,0 +1,7 @@
+class TrailingWhitespaceValidator < ActiveModel::EachValidator
+  def validate_each(record, attribute, value)
+    if value =~ /\s\z/
+      record.errors[attribute] << (options[:message] || I18n.t("validations.trailing whitespace"))
+    end
+  end
+end
\ No newline at end of file
index 0a5ee729d4652f1146e87b96e843abab114871de..c53ae19c8e014530174b64266fa239a328f14f71 100644 (file)
@@ -2134,9 +2134,6 @@ en:
       return to profile: Return to profile
       flash update success confirm needed: "User information updated successfully. Check your email for a note to confirm your new email address."
       flash update success: "User information updated successfully."
       return to profile: Return to profile
       flash update success confirm needed: "User information updated successfully. Check your email for a note to confirm your new email address."
       flash update success: "User information updated successfully."
-      leading whitespace: "has leading whitespace"
-      trailing whitespace: "has trailing whitespace"
-      invalid chars: "cannot contain invalid chars: %{invalid_chars}"
     confirm:
       heading: Check your email!
       introduction_1: |
     confirm:
       heading: Check your email!
       introduction_1: |
@@ -2565,3 +2562,7 @@ en:
       not_empty: "Redaction is not empty. Please un-redact all versions belonging to this redaction before destroying it."
       flash: "Redaction destroyed."
       error: "There was an error destroying this redaction."
       not_empty: "Redaction is not empty. Please un-redact all versions belonging to this redaction before destroying it."
       flash: "Redaction destroyed."
       error: "There was an error destroying this redaction."
+  validations:
+    leading whitespace: "has leading whitespace"
+    trailing whitespace: "has trailing whitespace"
+    invalid chars: "must not contain an invalid char: %{invalid_chars}"