Skip to content

ActiveSupports implementation of String#blank? is inconsistent with Ruby MRI #9992

@SamSaffron

Description

@SamSaffron

I have been looking at some perf issues around a large amount of blank? calls we are seeing at Discourse. see: #9958

I decided just to rewrite blank? in c for now, while we sort out what we do in AR and Active Support.

https://github.com/SamSaffron/fast_blank

While writing this I noticed the blank? implementation is not consistent with Ruby MRI.

[1] pry(main)> "\u2001".blank?
=> true
[2] pry(main)> "\u2001".strip.length
=> 1

#consistent
[3] pry(main)> "\r\n\v\f\s".strip.length
=> 0
[4] pry(main)> "\r\n\v\f\s".blank?
=> true

Meaning that my naive implementation that is consistent with strip etc, and could possibly be accepted into Ruby core is not a proper replacement for .blank?

Interestingly onigaruma neglects a few unicode spaces, making it even inconsistent with itself.

 # weird ass unicode crap
    #
    #1680, 180e, 200B, FEFF is missing from blank?
    #
    "\u00A0
    \u2000\u2001\u2002\u2003\u2004\u2005
    \u2006\u2007\u2008\u2009\u200A\u202F
    \u205F\u3000
    ".blank?
=> true

Is this unicode maddness really needed in blank?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions