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:
commit
13d75c40fd
5 changed files with 40 additions and 0 deletions
|
@ -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?`
|
* Deprecate `Notification::Event`'s `#children` and `#parent_of?`
|
||||||
|
|
||||||
* Change default serialization format of `MessageEncryptor` from `Marshal` to `JSON` for Rails 7.1.
|
* Change default serialization format of `MessageEncryptor` from `Marshal` to `JSON` for Rails 7.1.
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "active_support/core_ext/pathname/blank"
|
||||||
require "active_support/core_ext/pathname/existence"
|
require "active_support/core_ext/pathname/existence"
|
||||||
|
|
16
activesupport/lib/active_support/core_ext/pathname/blank.rb
Normal file
16
activesupport/lib/active_support/core_ext/pathname/blank.rb
Normal 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
|
|
@ -1,5 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
class Pathname
|
class Pathname
|
||||||
# Returns the receiver if the named file exists otherwise returns +nil+.
|
# Returns the receiver if the named file exists otherwise returns +nil+.
|
||||||
# <tt>pathname.existence</tt> is equivalent to
|
# <tt>pathname.existence</tt> is equivalent to
|
||||||
|
|
12
activesupport/test/core_ext/pathname/blank_test.rb
Normal file
12
activesupport/test/core_ext/pathname/blank_test.rb
Normal 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
|
Loading…
Reference in a new issue