Skip to content

Commit e272c89

Browse files
authored
Merge pull request #537 from aeroastro/feature/stop-changing-original-encoding
Always dup argument to preserve original encoding for force_encoding
2 parents 7106b03 + db9a489 commit e272c89

File tree

5 files changed

+89
-93
lines changed

5 files changed

+89
-93
lines changed

ext/json/ext/parser/parser.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,10 +1778,7 @@ static VALUE convert_encoding(VALUE source)
17781778
}
17791779

17801780
if (encindex == binary_encindex) {
1781-
if (OBJ_FROZEN(source)) {
1782-
source = rb_str_dup(source);
1783-
}
1784-
return rb_enc_associate_index(source, utf8_encindex);
1781+
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
17851782
}
17861783

17871784
return rb_str_conv_enc(source, rb_enc_from_index(encindex), rb_utf8_encoding());
@@ -1912,15 +1909,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
19121909
}
19131910

19141911

1915-
#line 1916 "parser.c"
1912+
#line 1913 "parser.c"
19161913
enum {JSON_start = 1};
19171914
enum {JSON_first_final = 10};
19181915
enum {JSON_error = 0};
19191916

19201917
enum {JSON_en_main = 1};
19211918

19221919

1923-
#line 824 "parser.rl"
1920+
#line 821 "parser.rl"
19241921

19251922

19261923
/*
@@ -1938,16 +1935,16 @@ static VALUE cParser_parse(VALUE self)
19381935
GET_PARSER;
19391936

19401937

1941-
#line 1942 "parser.c"
1938+
#line 1939 "parser.c"
19421939
{
19431940
cs = JSON_start;
19441941
}
19451942

1946-
#line 841 "parser.rl"
1943+
#line 838 "parser.rl"
19471944
p = json->source;
19481945
pe = p + json->len;
19491946

1950-
#line 1951 "parser.c"
1947+
#line 1948 "parser.c"
19511948
{
19521949
if ( p == pe )
19531950
goto _test_eof;
@@ -1981,7 +1978,7 @@ case 1:
19811978
cs = 0;
19821979
goto _out;
19831980
tr2:
1984-
#line 816 "parser.rl"
1981+
#line 813 "parser.rl"
19851982
{
19861983
char *np = JSON_parse_value(json, p, pe, &result, 0);
19871984
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1991,7 +1988,7 @@ cs = 0;
19911988
if ( ++p == pe )
19921989
goto _test_eof10;
19931990
case 10:
1994-
#line 1995 "parser.c"
1991+
#line 1992 "parser.c"
19951992
switch( (*p) ) {
19961993
case 13: goto st10;
19971994
case 32: goto st10;
@@ -2080,7 +2077,7 @@ case 9:
20802077
_out: {}
20812078
}
20822079

2083-
#line 844 "parser.rl"
2080+
#line 841 "parser.rl"
20842081

20852082
if (cs >= JSON_first_final && p == pe) {
20862083
return result;

ext/json/ext/parser/parser.rl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,7 @@ static VALUE convert_encoding(VALUE source)
673673
}
674674

675675
if (encindex == binary_encindex) {
676-
if (OBJ_FROZEN(source)) {
677-
source = rb_str_dup(source);
678-
}
679-
return rb_enc_associate_index(source, utf8_encindex);
676+
return rb_enc_associate_index(rb_str_dup(source), utf8_encindex);
680677
}
681678

682679
return rb_str_conv_enc(source, rb_enc_from_index(encindex), rb_utf8_encoding());

0 commit comments

Comments
 (0)