Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ascii_only? flag in strio_write #77

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,9 +915,6 @@ strio_extend(struct StringIO *ptr, long pos, long len)
if (pos > olen)
MEMZERO(RSTRING_PTR(ptr->string) + olen, char, pos - olen);
}
else {
rb_str_modify(ptr->string);
}
}

/*
Expand Down Expand Up @@ -1464,14 +1461,9 @@ strio_write(VALUE self, VALUE str)
}
}
else {
int cr0 = ENC_CODERANGE(ptr->string);
int cr = ENC_CODERANGE_UNKNOWN;
if (rb_enc_asciicompat(enc) && rb_enc_asciicompat(enc2)) {
cr = ENC_CODERANGE_AND(cr0, ENC_CODERANGE(str));
}
strio_extend(ptr, ptr->pos, len);
rb_str_modify(ptr->string);
memmove(RSTRING_PTR(ptr->string)+ptr->pos, RSTRING_PTR(str), len);
if (cr != cr0) ENC_CODERANGE_SET(ptr->string, cr);
}
RB_GC_GUARD(str);
ptr->pos += len;
Expand Down
6 changes: 6 additions & 0 deletions test/stringio/test_stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,12 @@ def test_coderange_after_overwrite
assert_predicate(s.string, :ascii_only?)
s.write "\u{431 43e 433 443 441}"
assert_not_predicate(s.string, :ascii_only?)

s = StringIO.new("\u{3042}")
s.rewind
assert_not_predicate(s.string, :ascii_only?)
s.write('aaaa')
assert_predicate(s.string, :ascii_only?)
end

def assert_string(content, encoding, str, mesg = nil)
Expand Down
Loading