1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #44485 from byroot/fix-pathname-blank

`Pathname.blank?` only returns true for `Pathname.new("")`
This commit is contained in:
Guillermo Iguaran 2022-02-20 00:32:48 -08:00 committed by GitHub
commit 13d75c40fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 0 deletions

View file

@ -1,3 +1,12 @@
* `Pathname.blank?` only returns true for `Pathname.new("")`
Previously it would end up calling `Pathname#empty?` which returned true
if the path existed and was an empty directory or file.
That behavior was unlikely to be expected.
*Jean Boussier*
* Deprecate `Notification::Event`'s `#children` and `#parent_of?`
* Change default serialization format of `MessageEncryptor` from `Marshal` to `JSON` for Rails 7.1.

View file

@ -1,3 +1,4 @@
# frozen_string_literal: true
require "active_support/core_ext/pathname/blank"
require "active_support/core_ext/pathname/existence"

View file

@ -0,0 +1,16 @@
# frozen_string_literal: true
require "pathname"
class Pathname
# An Pathname is blank if it's empty:
#
# Pathname.new("").blank? # => true
# Pathname.new(" ").blank? # => false
# Pathname.new("test).blank? # => false
#
# @return [true, false]
def blank?
to_s.empty?
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
require "pathname"
class Pathname
# Returns the receiver if the named file exists otherwise returns +nil+.
# <tt>pathname.existence</tt> is equivalent to

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
require_relative "../../abstract_unit"
require "active_support/core_ext/pathname/blank"
class PathnameBlankTest < ActiveSupport::TestCase
def test_blank
assert_predicate Pathname.new(""), :blank?
assert_not_predicate Pathname.new("test"), :blank?
assert_not_predicate Pathname.new(" "), :blank?
end
end