Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attribute_present? incorrectly returns true for empty strings #5314

Closed
Jacobkg opened this issue Mar 7, 2012 · 0 comments · Fixed by #5316
Closed

attribute_present? incorrectly returns true for empty strings #5314

Jacobkg opened this issue Mar 7, 2012 · 0 comments · Fixed by #5316

Comments

@Jacobkg
Copy link

Jacobkg commented Mar 7, 2012

The specification for attribute_present? says that it should return false if the attribute is nil or empty:

"Returns true if the specified attribute has been set by the user or by a database load and is neither nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings)."

However, the code is here:

def attribute_present?(attribute)
value = read_attribute(attribute)
!value.nil? || (value.respond_to?(:empty?) && !value.empty?)
end

The part that reads !value.nil? will return true for empty strings, and since it is an OR, will ignore the second part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants