Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1762 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

tango.text.locale.Posix modifies environment variables

Reported by: Deewiant Assigned to: kris
Priority: major Milestone: 0.99.9
Component: Tango Version: trunk
Keywords: Cc:

Description

Using Tango r5026, the following code:

import tango.text.locale.Locale;
import tango.io.Stdout;
import tango.sys.Environment;
void main() {
	Stdout(Environment.get("LANG")).newline;
}

Prints "en-GB.utf8" on my Linux system. If I remove the import of tango.text.locale.Locale, it prints the expected "en_GB.utf8". Note how there should be an underscore between "en" and "GB".

The problem is in tango.text.locale.Posix, which does a getenv("LC_ALL"), falling back to getenv("LANG"), and proceeds to replace all underscores in it with hyphens. It never takes a copy of the environment variable it retrieves, thus modifying the original.

It took me a while to figure out why running a Perl program from a D program caused it to emit warnings about not being able to find the locale...

I'm attaching a patch which takes a copy of the environment variable if it finds an underscore. Alternatively, you could be conservative and always take a copy.

Attachments

locale-dont-touch-env.patch (0.9 kB) - added by Deewiant on 10/29/09 14:50:00.

Change History

10/29/09 14:50:00 changed by Deewiant

  • attachment locale-dont-touch-env.patch added.

11/09/09 09:27:50 changed by kris

  • status changed from new to closed.
  • resolution set to fixed.

(In [5091]) fixes #1762 :: tango.text.locale.Posix modifies environment variables

Kudos to Deewiant