Skip to content

Commit 4d17ba4

Browse files
committed
Fix rb_enc_left_char_head()
* Fixes #3267
1 parent 124a255 commit 4d17ba4

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ New features:
55

66
Bug fixes:
77

8+
* Fix `rb_enc_left_char_head()` so it is not always `ArgumentError` (#3267, @eregon).
89

910
Compatibility:
1011

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4
1+
5

src/main/c/cext/encoding.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ int rb_enc_get_index(VALUE obj) {
226226
}
227227

228228
char* rb_enc_left_char_head(const char *start, const char *p, const char *end, rb_encoding *enc) {
229-
int length = start - end;
229+
if (p <= start || p >= end) {
230+
return p;
231+
}
232+
int length = end - start;
230233
int position = polyglot_as_i32(polyglot_invoke(RUBY_CEXT, "rb_enc_left_char_head",
231234
rb_tr_unwrap(rb_enc_from_encoding(enc)),
232235
rb_tr_unwrap(rb_str_new(start, length)),

0 commit comments

Comments
 (0)