Skip to content

Commit 3e71e6b

Browse files
committed
"Mongolian Vowel Separator" is not considered whitespace after Ruby 2.2
[Ruby Issue 9092](https://bugs.ruby-lang.org/issues/9092) updated Ruby from Unicode 6.1 to Unicode 7.0 ([commit here](ruby/ruby@64c81e4#diff-67d181a69374a75e4b8f706fa9b81fbc)). This patch was included in Ruby 2.2. From the [Unicode 6.3.0 release notes](http://www.unicode.org/versions/Unicode6.3.0/): The General_Category property value of U+180E MONGOLIAN VOWEL SEPARATOR has been changed from Zs to Cf. The values of other related properties such as Bidi_Class, White_Space, and Other_Default_Ignorable_Code_Point have been updated accordingly. After 2.2 shipped, Ruby's [[:space:]] Regexp expression [no longer matches U+180E](https://github.com/ruby/ruby/blob/9fefa6063797f94704c09663db13cea9e390eaba/enc/unicode/name2ctype.h#L2740-L2753). This updates fast_blank to treat U+180E properly in blank_as? Prior to this change, the tests fail on 2.2.2: 1) String provides a parity with active support function Failure/Error: expect("#{i.to_s(16)} #{c.blank_as?}").to eq("#{i.to_s(16)} #{c.blank2?}") - expected: "180e false" got: "180e true" - (compared using ==) # ./spec/fast_blank_spec.rb:22:in `block (3 levels) in <top (required)>' # ./spec/fast_blank_spec.rb:19:in `times' # ./spec/fast_blank_spec.rb:19:in `block (2 levels) in <top (required)>' It now passes on all the Rubies in the Travis matrix (RBX, 1.9, 2.0, 2.1, and 2.2).
1 parent 7d166e5 commit 3e71e6b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: ruby
22
rvm:
3+
- 2.2.2
34
- 2.1.6
45
- 2.0.0
56
- 1.9.3

ext/fast_blank/fast_blank.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ruby.h>
33
#include <ruby/encoding.h>
44
#include <ruby/re.h>
5+
#include <ruby/version.h>
56

67
#define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
78

@@ -13,6 +14,16 @@
1314
#define RSTRING_LEN(s) (RSTRING(s)->len)
1415
#endif
1516

17+
static int
18+
ruby_version_before_2_2()
19+
{
20+
if (RUBY_API_VERSION_MAJOR < 2 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR < 2)) {
21+
return 1;
22+
} else {
23+
return 0;
24+
}
25+
}
26+
1627
static VALUE
1728
rb_str_blank_as(VALUE str)
1829
{
@@ -38,7 +49,6 @@ rb_str_blank_as(VALUE str)
3849
case 0x85:
3950
case 0xa0:
4051
case 0x1680:
41-
case 0x180e:
4252
case 0x2000:
4353
case 0x2001:
4454
case 0x2002:
@@ -57,6 +67,8 @@ rb_str_blank_as(VALUE str)
5767
case 0x3000:
5868
/* found */
5969
break;
70+
case 0x180e:
71+
if (ruby_version_before_2_2()) break;
6072
default:
6173
return Qfalse;
6274
}

0 commit comments

Comments
 (0)