Skip to content

Commit

Permalink
Hex notation semantics for one byte characters seem to have changed b…
Browse files Browse the repository at this point in the history
…etween Perl 5.20 onwards, Github issue xslate#88
  • Loading branch information
Michael Kröll committed Apr 15, 2016
1 parent 51a86b2 commit e563bfe
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions t/900_bugs/046_issue88.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,37 @@ use warnings;
use Test::More;

use utf8;
use Encode;
use Text::Xslate 'mark_raw';
my $xslate = Text::Xslate->new();

# Hex notation semantics for one byte characters seem to have changed between Perl 5.20 onwards
# With recent Perl versions, onbe byte characters from hex notation need to be explicitly decoded as UTF-8 characters
my $aumlaut_utf8_character_from_hex_notation = Encode::decode_utf8(
Encode::encode_utf8("\x{c4}")
);
my $smiley_from_hex_notation = "\x{263A}";

# No UTF-8 in the template
is $xslate->render_string('<: $string :>', {string => "Ä"}) => 'Ä';
# As long as both template and parameter strings are single-byte, we are fine
is $xslate->render_string('<: $string :>', {string => "\x{c4}"}) => 'Ä';
is $xslate->render_string('<: $string :>', {string => $smiley_from_hex_notation}) => '';

# UTF-8 in the template, literal and utf-8 decoded from hex notation in parameters
is $xslate->render_string('あ<: $string :>', {string => "Ä"}) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => "\x{c4}"}) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => $aumlaut_utf8_character_from_hex_notation }) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => $smiley_from_hex_notation }) => 'あ☺';

# No UTF-8 in the template, mark_raw, literal and hex notation in parameters
is $xslate->render_string('<: $string :>', {string => mark_raw("Ä")}) => 'Ä';
# Test one-byte character coming in via hex notation
is $xslate->render_string('<: $string :>', {string => mark_raw("\x{c4}")}) => 'Ä';
is $xslate->render_string('<: $string :>', {string => mark_raw($smiley_from_hex_notation)}) => '';

is $xslate->render_string('あ<: $string :>', {string => mark_raw("Ä")}) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => mark_raw("\x{c4}")}) => 'あÄ';
# UTF-8 in the template, mark_raw, literal and utf-8 decoded from hex notation in parameters
is $xslate->render_string('あ<: $string :>', {string => mark_raw("Ä")}) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => mark_raw($aumlaut_utf8_character_from_hex_notation )}) => 'あÄ';
is $xslate->render_string('あ<: $string :>', {string => $smiley_from_hex_notation }) => 'あ☺';

done_testing();

0 comments on commit e563bfe

Please sign in to comment.