MacRuby : bug : regexp
diff --git a/re.c b/re.c
index 6cdfe85..acf6cb5 100644
--- a/re.c
+++ b/re.c
@@ -89,6 +89,25 @@ regexp_finalize_imp(void *rcv, SEL sel)
}
}
+static bool
+is_octal_literal(UChar *chars, long length)
+{
+ bool ret = false;
+ int i;
+ for(i = 0; i < length; i++) {
+ UChar c = chars[i];
+ if (!rb_isdigit(c)) {
+ break;
+ }
+ if (c >= '8') {
+ return false;
+ }
+ ret = true;
+ }
+
+ return ret && i >= 2;
+}
+
// Work around ICU limitations.
static void
sanitize_regexp_string(UChar **chars_p, long *chars_len_p)
@@ -142,7 +161,20 @@ sanitize_regexp_string(UChar **chars_p, long *chars_len_p)
break;
}
UChar c = chars[i];
- if (c >= '0' && c <= '9') {
+ if (rb_isdigit(c)) {
+ if (is_octal_literal(&chars[i], chars_len)) {
+ // Handling for octal literals.
+ if (c > '0') {
+ // ICU need the string as octal literal \0ooo format.
+ chars = (UChar *)xrealloc(chars, sizeof(UChar) * (chars_len + 1));
+ memmove(&chars[i + 1], &chars[i],
+ sizeof(UChar) * (chars_len - i));
+ chars[i] = '0';
+ chars_len++;
+ }
+ break;
+ }
+
assert(n < 10);
buf[n++] = (char)c;
}
time = "Wed, 18 Apr 2012 05:36:28 GMT"
p time =~ /[\x00-\x1F]/ # hex
p time =~ /[\00-\037]/ # oct
str = "abcdefg"
str =~ /([\0141-\143]+)/
p $1