It took a little editing but I was able to reproduce this (Linux / Perl 5.26). Note that AFAIK PerlMonks defaults to the Latin1 character set encoding, so as opposed to the file you get from the [download] link, I am assuming that your source code file is correctly encoded in valid UTF-8 and contains the correctly encoded characters "É" and "é". In my post below I am using the <pre> instead of <code> tags (and a few other replacements) in order to get PerlMonks to display the post correctly. For posting on PerlMonks, personally I would not use utf8; and use \x{00C9} escapes instead, although then again, if I do that with your code, none of the input strings are flagged as UTF-8. (Update: With \N{U+00C9}, they do get flagged as UTF8.)

It appears that HTML::Entities's decode_entities does not enable the UTF8 flag on the string, so that the non-UTF8 string "&Eacute;dition limit&eacute;e." does not get upgraded.

#!/usr/bin/env perl
use warnings;
use strict;
use utf8;
use open qw/:std :utf8/;
use HTML::Entities;
use Devel::Peek;

my @strs = ("Édition limitÉe.",
	"Édition limit&Eacute;e.",
	"&Eacute;dition limit&Eacute;e.");
for my $str (@strs) {
	$str = decode_entities($str);
	Dump($str);
	$str = lc($str);
	Dump($str);
	print "{$str}\n";
}

__END__

# Output edited for brevity
SV = ... FLAGS = (POK,pPOK,UTF8)
  PV = 0xf667c0 "\303\211dition limit\303\211e."\0 [UTF8 "\x{c9}dition limit\x{c9}e."]
SV = ... FLAGS = (POK,pPOK,UTF8)
  PV = 0xf667c0 "\303\251dition limit\303\251e."\0 [UTF8 "\x{e9}dition limit\x{e9}e."]
{édition limitée.}
SV = ... FLAGS = (POK,pPOK,UTF8)
  PV = 0xffde20 "\303\211dition limit\303\211e."\0 [UTF8 "\x{c9}dition limit\x{c9}e."]
SV = ... FLAGS = (POK,pPOK,UTF8)
  PV = 0xffde20 "\303\251dition limit\303\251e."\0 [UTF8 "\x{e9}dition limit\x{e9}e."]
{édition limitée.}
SV = ... FLAGS = (POK,pPOK)
  PV = 0xfe3440 "\311dition limit\311e."\0
SV = ... FLAGS = (POK,pPOK)
  PV = 0xfe3440 "\311dition limit\311e."\0
{Édition limitÉe.}

The "correct" way to solve this depends a bit on where these strings you are getting are coming from. Are they all embedded in your source code? Are you reading them from a file? If so, are you opening the files with the correct layers, that is for exaple, open my $fh, '<:encoding(UTF-8)', ...?

Update: In the code, changed all é to É and &eacute; to &Eacute; to make the effects more clear. (Also, I can't reproduce the dependence on the -w switch that 1nickt reported.)


In reply to Re: Unexpected interaction between decode_entities() and lc() by haukex
in thread Unexpected interaction between decode_entities() and lc() by kurisuto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.