diff --git a/dist/Storable/Storable.xs b/dist/Storable/Storable.xs index 1058841b921e..3be8904e482d 100644 --- a/dist/Storable/Storable.xs +++ b/dist/Storable/Storable.xs @@ -2960,6 +2960,19 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv) keyval = SvPV(key, keylen_tmp); keylen = keylen_tmp; if (SvUTF8(key)) { + +#ifdef utf8_to_bytes_overwrite + + /* If we are able to downgrade here; that means that we have a + * key which only had chars 0-255, but was utf8 encoded. */ + if (utf8_to_bytes_overwrite( (U8**) &keyval, &keylen_tmp)) { + keylen = keylen_tmp; + flags |= SHV_K_WASUTF8; + } + else { + flags |= SHV_K_UTF8; + } +#else const char *keysave = keyval; bool is_utf8 = TRUE; @@ -2982,6 +2995,7 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv) to assign back to keylen. */ flags |= SHV_K_UTF8; } +#endif } if (flagged_hash) { @@ -3000,8 +3014,12 @@ static int store_hash(pTHX_ stcxt_t *cxt, HV *hv) WLEN(keylen); if (keylen) WRITE(keyval, keylen); + +#ifndef utf8_to_bytes_overwrite + if (flags & SHV_K_WASUTF8) Safefree (keyval); +#endif } /* diff --git a/dist/Storable/lib/Storable.pm b/dist/Storable/lib/Storable.pm index 3441b1c6f182..e33c20d1bb6c 100644 --- a/dist/Storable/lib/Storable.pm +++ b/dist/Storable/lib/Storable.pm @@ -30,7 +30,7 @@ our @EXPORT_OK = qw( our ($canonical, $forgive_me); BEGIN { - our $VERSION = '3.35'; + our $VERSION = '3.36'; } our $recursion_limit;