december has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow seekers of enlightenment,
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:
$testString = "/usr/home/december/public_html/experiments/html/files/b +lë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\/.]+)$/);
prints:
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
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.
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.
|
---|