Issue #15816 has been updated by jeremyevans0 (Jeremy Evans).

File casecmp-lowercase.patch added

The documentation of `String#casecmp` does not specify how it is is implemented, so it seems fair to consider switching.  However, this change is likely to cause backwards compatibility issues.  While it seems unlikely there are many applications relying on the current behavior, I would guess there are at least a few.

Considering that `String#casecmp?` uses lowercase and not uppercase, I think making such a change is reasonable, but we may want to delay making this change until Ruby 3.

Attached is a patch if we want to make this change.

 

----------------------------------------
Bug #15816: String#casecmp compares uppercase characters instead of lowercase
https://bugs.ruby-lang.org/issues/15816#change-77961

* Author: jonathanhefner (Jonathan Hefner)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
The current implementation of `String#casecmp` converts characters to uppercase before comparing them.  However, all references I've found for `strcasecmp` (the C function on which `String#casecmp` is based) indicate characters should be converted to lowercase before being compared.

For example, [this man page](http://manpages.ubuntu.com/manpages/eoan/man3/strcasecmp.3.html) says:

> The POSIX.1-2008 standard says ... shall behave as if the strings had been converted to lowercase and then a byte comparison performed.

The difference in behavior is apparent when comparing / sorting strings containing `[`, `\`, `]`, `^`, `_`, or `` ` `` (the characters that occur between `Z` and `a`).  Converting to lowercase sorts these punctuation characters before `A`-`z` along with most of the other punctuation in ASCII, but converting to uppercase sorts these characters after `A`-`z` instead.


---Files--------------------------------
casecmp-lowercase.patch (1.3 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>