ext/oj/load.c in oj-1.0.6 vs ext/oj/load.c in oj-1.1.0
- old
+ new
@@ -73,10 +73,11 @@
static VALUE read_true(ParseInfo pi);
static VALUE read_false(ParseInfo pi);
static VALUE read_nil(ParseInfo pi);
static void next_non_white(ParseInfo pi);
static char* read_quoted_value(ParseInfo pi);
+static void skip_comment(ParseInfo pi);
/* This XML parser is a single pass, destructive, callback parser. It is a
* single pass parse since it only make one pass over the characters in the
* XML document string. It is destructive because it re-uses the content of
@@ -98,10 +99,13 @@
case '\t':
case '\f':
case '\n':
case '\r':
break;
+ case '/':
+ skip_comment(pi);
+ break;
default:
return;
}
}
}
@@ -273,10 +277,40 @@
obj = ca->objs[id - 1];
}
return obj;
}
+static void
+skip_comment(ParseInfo pi) {
+ pi->s++; // skip first /
+ if ('*' == *pi->s) {
+ pi->s++;
+ for (; '\0' != *pi->s; pi->s++) {
+ if ('*' == *pi->s && '/' == *(pi->s + 1)) {
+ pi->s++;
+ return;
+ } else if ('\0' == *pi->s) {
+ raise_error("comment not terminated", pi->str, pi->s);
+ }
+ }
+ } else if ('/' == *pi->s) {
+ for (; 1; pi->s++) {
+ switch (*pi->s) {
+ case '\n':
+ case '\r':
+ case '\f':
+ case '\0':
+ return;
+ default:
+ break;
+ }
+ }
+ } else {
+ raise_error("invalid comment", pi->str, pi->s);
+ }
+}
+
static VALUE
read_next(ParseInfo pi, int hint) {
VALUE obj;
next_non_white(pi); // skip white space
@@ -305,11 +339,14 @@
if (TIME_HINT == hint) {
obj = read_time(pi);
} else {
obj = read_num(pi);
}
- break;
+ break;
+ case 'I':
+ obj = read_num(pi);
+ break;
case 't':
obj = read_true(pi);
break;
case 'f':
obj = read_false(pi);
@@ -638,9 +675,20 @@
if ('-' == *pi->s) {
pi->s++;
neg = 1;
} else if ('+' == *pi->s) {
pi->s++;
+ }
+ if ('I' == *pi->s) {
+ if (0 != strncmp("Infinity", pi->s, 8)) {
+ raise_error("number or other value", pi->str, pi->s);
+ }
+ pi->s += 8;
+ if (neg) {
+ return rb_float_new(-INFINITY);
+ } else {
+ return rb_float_new(INFINITY);
+ }
}
for (; '0' <= *pi->s && *pi->s <= '9'; pi->s++) {
n = n * 10 + (*pi->s - '0');
if (NUM_MAX <= n) {
big = 1;