perlquestion
december
<p>Hello, fellow seekers of enlightenment,</p>
<p>I'm trying to construct a simple regex that checks if a variable contains characters valid in a unix path. The regex works as it should when there are no umlauts in the string, but when testing different inputs, I noticed it refuses to match any umlauts. What bugs me, is that it does match the exact same string when I use a variable, but not when handed down by $ENV{'PATH_TRANSLATED'} - which probably is a non-encoded 8bit string. A shortened example:</p>
<p><code>
$testString = "/usr/home/december/public_html/experiments/html/files/blëh.txt";
$fileAsked = $ENV{'PATH_TRANSLATED'};
print "Trying with: $testString\n";
print "Trying with: $fileAsked\n";
print "VALID1\n" if ($testString =~ /^([\w\s\/.]+)$/);
print "VALID2\n" if ($fileAsked =~ /^([\w\s\/.]+)$/);
print "SUCCEEDED1\n" if (utf8::upgrade($testString));
print "SUCCEEDED2\n" if (utf8::upgrade($fileAsked));
print "VALID3\n" if ($testString =~ /^([\w\s\/.]+)$/);
print "VALID4\n" if ($fileAsked =~ /^([\w\s\/.]+)$/);
</code></p>
<p>prints:</p>
<p><code>
Trying with: /usr/home/december/public_html/experiments/html/files/blëh.txt
Trying with: /usr/home/december/public_html/experiments/html/files/blëh.txt
SUCCEEDED1
SUCCEEDED2
VALID3
</code></p>
<p>Note that both strings and regex's are exactly the same, but after conversion, one matches, and the other doesn't. I suspect some utf8 problems, or a wrong charset used for \w. Perl version is 5.8.3.</p>
<p>How do I make the \w match umlauts consistently? Do I need to set a locale even for utf8? This behavior doesn't seem logical to me.</p>