Skip to content

Commit

Permalink
Revert "Avoid generating malformed UTF-8 and replacement characters b…
Browse files Browse the repository at this point in the history
…y interpolating the variable as-is if it is not a valid UTF-8 sequence (nc), Github issue xslate#88"

This reverts commit 723f10dfc38202c863c1851a73228b03b8604aba.
  • Loading branch information
Michael Kröll committed Apr 20, 2016
1 parent be85c87 commit 7bae469
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 55 deletions.
1 change: 0 additions & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ t/900_bugs/042_perl59_issue.t
t/900_bugs/043_issue107.t
t/900_bugs/044_empty_result.t
t/900_bugs/045_issue130.t
t/900_bugs/046_issue88.t
t/900_bugs/issue79/tmpl/contentA.tt
t/900_bugs/issue79/tmpl/contentB.tt
t/900_bugs/issue79/tmpl/wrapperA.tt
Expand Down
4 changes: 2 additions & 2 deletions lib/Text/Xslate/PP/State.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ sub print {
if(defined ${$sv}) {
$st->{output} .=
(utf8::is_utf8($st->{output}) && !utf8::is_utf8(${$sv}))
? eval {$st->encoding->decode(${$sv}, Encode::FB_CROAK())} || ${$sv}
? $st->encoding->decode(${$sv})
: ${$sv};
}
else {
Expand All @@ -188,7 +188,7 @@ sub print {
$sv =~ s/($Text::Xslate::PP::html_metachars)/$Text::Xslate::PP::html_escape{$1}/xmsgeo;
$st->{output} .=
(utf8::is_utf8($st->{output}) && !utf8::is_utf8($sv))
? eval {$st->encoding->decode($sv, Encode::FB_CROAK())} || $sv
? $st->encoding->decode($sv)
: $sv;
}
else {
Expand Down
32 changes: 3 additions & 29 deletions src/Text-Xslate.xs
Original file line number Diff line number Diff line change
Expand Up @@ -541,39 +541,19 @@ tx_unmark_raw(pTHX_ SV* const str) {
/* does sv_catsv_nomg(dest, src), but significantly faster */
STATIC_INLINE void
tx_sv_cat(pTHX_ SV* const dest, SV* const src) {
STRLEN len;
const char* pv = SvPV_const(src, len);

if(!SvUTF8(dest) && SvUTF8(src)) {
sv_utf8_upgrade(dest);
}

if(SvUTF8(dest) == SvUTF8(src)
|| is_utf8_string((const U8 *)pv, len)) {
{
STRLEN len;
const char* const pv = SvPV_const(src, len);
STRLEN const dest_cur = SvCUR(dest);
char* const d = SvGROW(dest, dest_cur + len + 1 /* count '\0' */);

SvCUR_set(dest, dest_cur + len);
Copy(pv, d + dest_cur, len + 1 /* copy '\0' */, char);
}
else {
STRLEN const dest_cur = SvCUR(dest);
/* Longest UTF-8 representation of each char is 2 octets. */
char* const d_start = SvGROW(dest, dest_cur + 2 * len + 1 /* count '\0' */);
char* d = d_start + dest_cur;

while(len--) {
const U8 c = *pv++;
if (UTF8_IS_INVARIANT(c)) {
*(d++) = c;
} else {
*(d++) = UTF8_EIGHT_BIT_HI(c);
*(d++) = UTF8_EIGHT_BIT_LO(c);
}
}
*d = '\0';
SvCUR_set(dest, d - d_start);
}
}

static void /* doesn't care about raw-ness */
Expand All @@ -583,8 +563,6 @@ tx_sv_cat_with_html_escape_force(pTHX_ SV* const dest, SV* const src) {
const char* const end = cur + len;
STRLEN const dest_cur = SvCUR(dest);
char* d;
const U32 upgrade_on_copy = SvUTF8(dest) && !SvUTF8(src)
&& !is_utf8_string((const U8 *)cur, len);

(void)SvGROW(dest, dest_cur + ( len * ( sizeof(""") - 1) ) + 1);
if(!SvUTF8(dest) && SvUTF8(src)) {
Expand Down Expand Up @@ -617,10 +595,6 @@ tx_sv_cat_with_html_escape_force(pTHX_ SV* const dest, SV* const src) {
// CopyToken("'", d);
CopyToken("'", d);
}
else if (upgrade_on_copy && !UTF8_IS_INVARIANT(c)) {
*(d++) = UTF8_EIGHT_BIT_HI(c);
*(d++) = UTF8_EIGHT_BIT_LO(c);
}
else {
*(d++) = c;
}
Expand Down
23 changes: 0 additions & 23 deletions t/900_bugs/046_issue88.t

This file was deleted.

0 comments on commit 7bae469

Please sign in to comment.