Skip to content
Browse files

Treat invalid characters as single byte for length

  • Loading branch information...
1 parent f38f73c commit 96534269834c77d98f36a37049b816b392b5eb6f @dbussink dbussink committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 vm/builtin/string.cpp
View
9 vm/builtin/string.cpp
@@ -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) {

0 comments on commit 9653426

Please sign in to comment.
Something went wrong with that request. Please try again.