develooper Front page | perl.perl5.porters | Postings from February 2018

[perl #132901] setlocale's return value is broken

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
February 25, 2018 20:39
Subject:
[perl #132901] setlocale's return value is broken
Message ID:
rt-4.0.24-3831-1519591152-625.132901-15-0@perl.org
On Sun, 25 Feb 2018 11:47:40 -0800, public@khwilliamson.com wrote:
> On 02/25/2018 10:21 AM, Slaven Rezic wrote:
> > $ env LC_ALL=de_DE.UTF-8 ./perl -Ilib -MTest::More=no_plan
> > -MPOSIX=setlocale,LC_ALL -e 'is setlocale(LC_ALL), "de_DE.UTF-8"'
> > not ok 1
> > #   Failed test at -e line 1.
> > #          got: '�^'
> > #     expected: 'de_DE.UTF-8'
> > 1..1
> > # Looks like you failed 1 test of 1.
> 
> I realize now in looking at the tests why there is not already a test
> for this.  The reason is that the return from setlocale is explictly
> documented to be opaque; not necessarily human readable.  It is
> required
> only that a future setlocale() changing the locale to the value
> returned
> properly work.
> 
> That said, I know of no system that actually doesn't return a human
> readable name, but it may not exactly match the input one.  It might
> be
> missing (or gained) a hyphen, or the casing may be different.  And
> where
> individual categories aren't all the same, LC_ALL is represented
> differently on different systems.  (On Linux, it is a list of the
> individual categories and their values with each component separated
> by
> a semi-colon).
> 
> I suppose a test could be written which strips off the hyphens and
> lowercases everything, and then do the comparison, and then we could
> skip or adjust this test if any platforms showed up if failed for.
> 
> I'm open to hearing ideas.

Tests that need constant tweaking are the maintainer’s bane.  Could we do some kind of ‘loose match’ that requires at least, say, four or five of the same ASCII alphanumerical characters to be present in both strings, and in the right order?

If you transform de_DE.UTF-8 to /d.*e.*d.*e.*/aai this might actually work and require little tweaking in the long term.  It would certainly have caught the bug.

This would work:

$regexp = substr fc($locale) =~ y/a-z0-9//cdr, 0, 4, =~ s/./$&.*/gr;

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=132901

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About