GithubHelp home page GithubHelp logo

Comments (6)

caspg avatar caspg commented on May 31, 2024

Since we can get an empty string (but we don't want to check if this param is present), we could use for example #blank_value? method and change:
https://github.com/lotus/validations/blob/master/lib/lotus/validations/attribute.rb#L213-L215

def skip?
  @value.nil?
end

to:

def skip?
  blank_value?
end

@jodosha What do you think?

from validations.

runlevel5 avatar runlevel5 commented on May 31, 2024

@caspg thanks for the bug report, can you verify if this also the case for using lotus/validation alone with other framework?

from validations.

caspg avatar caspg commented on May 31, 2024

@joneslee85 I'm not sure how can I use lotus/validation for params in other frameworks. But sinatra and rails, also return empty string ("") as a param, when you submit empty input. So I believe that problem will be the same. That's why I think we should check in skip? method if value is nil or empty string.

from validations.

jodosha avatar jodosha commented on May 31, 2024

@caspg Thanks for reporting this issue 👍

That strategy that involves "blank" fixes your problem, but creates a new one.

class SizeValidator
  include Lotus::Attributes
  attribute :tags, size: 3
end

SizeValidator.new.valid? # => true - OK
SizeValidator.new(tags: []).valid? # => true - OUCH

But you give us a great hint ✨

Please check if the attached PR fixes your case.

from validations.

caspg avatar caspg commented on May 31, 2024

@jodosha With PR it works great, thanks 😃

from validations.

jodosha avatar jodosha commented on May 31, 2024

@caspg 🎩

from validations.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.