Skip to content

Commit

Permalink
Treat invalid characters as single byte for length
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Dec 28, 2012
1 parent f38f73c commit 9653426
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vm/builtin/string.cpp
Expand Up @@ -1706,9 +1706,12 @@ namespace rubinius {
for(i = 0; i < k && p < e; i++) {
int c = Encoding::precise_mbclen(p, e, enc);

if(!ONIGENC_MBCLEN_CHARFOUND_P(c)) return nil<Fixnum>();

p += ONIGENC_MBCLEN_CHARFOUND_LEN(c);
// If it's an invalid byte, just treat it as a single byte
if(!ONIGENC_MBCLEN_CHARFOUND_P(c)) {
++p;
} else {
p += ONIGENC_MBCLEN_CHARFOUND_LEN(c);
}
}

if(i < k) {
Expand Down

0 comments on commit 9653426

Please sign in to comment.