Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Collection of useful custom validators for Rails applications, including:
Note InnValidator and other Russian specific validators could be found at validates_russian gem
Add this line to your application's Gemfile:
gem 'validates'
Or install it yourself as:
$ gem install 'validates'
For most of the validators you just want to add this line to your model:
validates :attribute, <validator_underscore>: true
where <validator_underscore>
is an underscored, lowercase form from the validator's name (see the examples section below).
Because this is the successor of ActiveModel::Validations::LengthValidator
validator, it inherits all the options of the latter, such as :is
, :minimum
,
:maximum
, etc. Another option, which you may be interested in is :select
option,
which allows you to filter the collection of the associated objects.
class User < ActiveRecord::Base
validates :email, :email => true
validates :site, :url => true, :allow_blank => true
end
class Company < ActiveRecord::Base
# note AssociationLengthValidator is inherited from ActiveModel::Validations::LengthValidator
# http://api.rubyonrails.org/classes/ActiveModel/Validations/LengthValidator.html
# so you can easily use standard options like :is, :minimum, :maximum, etc.
validates :employees,
:association_length => {
:minimum => 1,
:select => ->(employee) { employee.name.in? ["Mike", "John"] }
}
validates :employees, :association_length => { :minimum => 1, :select => :employees_filter }
def employees_filter(employees)
employees.select { |employee| employee.name.in? ["Mike", "John"] }
end
end
class Page < ActiveRecord::Base
validates :slug, :slug => true
end
class Content < ActiveRecord::Base
# Validates URI component.
# URI component must be of the following type:
# :ABS_URI, :REL_URI, :URI_REF, :ABS_URI_REF, :REL_URI_REF, :ESCAPED, :UNSAFE, :SCHEME,
# :USERINFO, :HOST, :PORT, :OPAQUE, :REGISTRY, :ABS_PATH, :REL_PATH, :QUERY or :FRAGMENT.
# These types are provided URI library. For more info see URI::DEFAULT_PARSER.regexp.
validates :path, :uri_component => { :component => :ABS_PATH }
end
Please see CONTRIBUTING.md for details.
Originally written by Mikhail Stolbov. Maintained by kaize.
Thank you to all our amazing contributors!
validates is Copyright © 2012-2014 Mikhail Stolbov and kaize. It is free software, and may be redistributed under the terms specified in the LICENSE file.
FAQs
Unknown package
We found that validates demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.