summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2016-07-26 11:27:14 +0200
committerFlorian Frank <flori@ping.de>2016-07-26 11:42:18 +0200
commit047814c7a6916bde393e6080c98385c8170d3f98 (patch)
tree8c35b1e2abf068c33af2f2268a1bc6ab80da2780 /ext/json
parentbb5b67741c20c8a53f2e81985fafccbeb750818c (diff)
downloadjson-047814c7a6916bde393e6080c98385c8170d3f98.tar.gz
Fix issue #296 when parsing frozen strings
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/ext/parser/parser.c19
-rw-r--r--ext/json/ext/parser/parser.rl3
2 files changed, 14 insertions, 8 deletions
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index 975a267..0dae674 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -1670,6 +1670,9 @@ static VALUE convert_encoding(VALUE source)
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *enc = rb_enc_get(source);
if (enc == rb_ascii8bit_encoding()) {
+ if (OBJ_FROZEN(source)) {
+ source = rb_str_dup(source);
+ }
FORCE_UTF8(source);
} else {
source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
@@ -1805,7 +1808,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
}
-#line 1809 "parser.c"
+#line 1812 "parser.c"
enum {JSON_start = 1};
enum {JSON_first_final = 10};
enum {JSON_error = 0};
@@ -1813,7 +1816,7 @@ enum {JSON_error = 0};
enum {JSON_en_main = 1};
-#line 717 "parser.rl"
+#line 720 "parser.rl"
/*
@@ -1830,16 +1833,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1834 "parser.c"
+#line 1837 "parser.c"
{
cs = JSON_start;
}
-#line 733 "parser.rl"
+#line 736 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1843 "parser.c"
+#line 1846 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1873,7 +1876,7 @@ st0:
cs = 0;
goto _out;
tr2:
-#line 709 "parser.rl"
+#line 712 "parser.rl"
{
char *np = JSON_parse_value(json, p, pe, &result, 0);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1883,7 +1886,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1887 "parser.c"
+#line 1890 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1972,7 +1975,7 @@ case 9:
_out: {}
}
-#line 736 "parser.rl"
+#line 739 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index c67634b..dd24cf9 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -565,6 +565,9 @@ static VALUE convert_encoding(VALUE source)
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *enc = rb_enc_get(source);
if (enc == rb_ascii8bit_encoding()) {
+ if (OBJ_FROZEN(source)) {
+ source = rb_str_dup(source);
+ }
FORCE_UTF8(source);
} else {
source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());