summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorKOBAYASHI Shuji <[email protected]>2019-10-22 21:56:40 +0900
committerKOBAYASHI Shuji <[email protected]>2019-10-22 21:56:40 +0900
commit41c43234a7870af32cf4bec830229df0dea1c142 (patch)
treeb7306e4b4c51f0d5172eb7e33cae633d6c591e9b /src/string.c
parent1aacde20fa6b2a4e5fd397e6117d789b93b166fb (diff)
downloadmruby-41c43234a7870af32cf4bec830229df0dea1c142.tar.gz
mruby-41c43234a7870af32cf4bec830229df0dea1c142.zip
Fix incorrect `MRB_STR_ASCII` flag update in `mrb_str_dump`
### Example (with `MRB_UTF8_STRING`) ```ruby s = "\u3042" p s.size s.dump p s.size ``` #### Before this patch: ``` 1 3 ``` #### After this patch: ``` 1 1 ```
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c
index d3774f8c4..6ab9a1ff7 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1388,8 +1388,13 @@ str_escape(mrb_state *mrb, mrb_value str, mrb_bool inspect)
}
mrb_str_cat_lit(mrb, result, "\"");
#ifdef MRB_UTF8_STRING
- mrb_str_ptr(str)->flags |= ascii_flag;
- mrb_str_ptr(result)->flags |= ascii_flag;
+ if (inspect) {
+ mrb_str_ptr(str)->flags |= ascii_flag;
+ mrb_str_ptr(result)->flags |= ascii_flag;
+ }
+ else {
+ RSTR_SET_ASCII_FLAG(mrb_str_ptr(result));
+ }
#endif
return result;