make QProcessEnvironment on Windows preserve variable name case
while windows itself does not care which case the variable names are in, they may be passed to unix tools which *do* care. note that this uses true case folding for string comparisons while windows uses uppercasing. this means that "ess" and "eß" will be considered the same by us, while not by windows. this is not expected to have real-world impact, particularly because non-ascii variable names are not used much. Task-number: QTCREATORBUG-3110 Reviewed-by: thiago Reviewed-by: dt (cherry picked from commit f3db5603871928ebed43a085a496397e65952b39)
This commit is contained in:
parent
3ab236d77b
commit
4212ee7ec7
@ -145,7 +145,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
*/
|
*/
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
static inline QProcessEnvironmentPrivate::Key prepareName(const QString &name)
|
static inline QProcessEnvironmentPrivate::Key prepareName(const QString &name)
|
||||||
{ return name.toUpper(); }
|
{ return QProcessEnvironmentPrivate::Key(name); }
|
||||||
static inline QString nameToString(const QProcessEnvironmentPrivate::Key &name)
|
static inline QString nameToString(const QProcessEnvironmentPrivate::Key &name)
|
||||||
{ return name; }
|
{ return name; }
|
||||||
static inline QProcessEnvironmentPrivate::Value prepareValue(const QString &value)
|
static inline QProcessEnvironmentPrivate::Value prepareValue(const QString &value)
|
||||||
|
@ -85,7 +85,15 @@ class QProcessEnvironmentPrivate: public QSharedData
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
typedef QString Key;
|
class Key : public QString
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Key() {}
|
||||||
|
explicit Key(const QString &other) : QString(other) {}
|
||||||
|
Key(const Key &other) : QString(other) {}
|
||||||
|
bool operator==(const Key &other) const { return !compare(other, Qt::CaseInsensitive); }
|
||||||
|
};
|
||||||
|
|
||||||
typedef QString Value;
|
typedef QString Value;
|
||||||
#else
|
#else
|
||||||
typedef QByteArray Key;
|
typedef QByteArray Key;
|
||||||
@ -100,6 +108,10 @@ public:
|
|||||||
QStringList keys() const;
|
QStringList keys() const;
|
||||||
void insert(const Hash &hash);
|
void insert(const Hash &hash);
|
||||||
};
|
};
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
Q_DECLARE_TYPEINFO(QProcessEnvironmentPrivate::Key, Q_MOVABLE_TYPE);
|
||||||
|
inline uint qHash(const QProcessEnvironmentPrivate::Key &key) { return qHash(key.toCaseFolded()); }
|
||||||
|
#endif
|
||||||
|
|
||||||
class QProcessPrivate : public QIODevicePrivate
|
class QProcessPrivate : public QIODevicePrivate
|
||||||
{
|
{
|
||||||
|
@ -285,17 +285,19 @@ static QByteArray qt_create_environment(const QProcessEnvironmentPrivate::Hash &
|
|||||||
QProcessEnvironmentPrivate::Hash copy = environment;
|
QProcessEnvironmentPrivate::Hash copy = environment;
|
||||||
|
|
||||||
// add PATH if necessary (for DLL loading)
|
// add PATH if necessary (for DLL loading)
|
||||||
if (!copy.contains(QLatin1String("PATH"))) {
|
QProcessEnvironmentPrivate::Key pathKey(QLatin1String("PATH"));
|
||||||
|
if (!copy.contains(pathKey)) {
|
||||||
QByteArray path = qgetenv("PATH");
|
QByteArray path = qgetenv("PATH");
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
copy.insert(QLatin1String("PATH"), QString::fromLocal8Bit(path));
|
copy.insert(pathKey, QString::fromLocal8Bit(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add systemroot if needed
|
// add systemroot if needed
|
||||||
if (!copy.contains(QLatin1String("SYSTEMROOT"))) {
|
QProcessEnvironmentPrivate::Key rootKey(QLatin1String("SystemRoot"));
|
||||||
QByteArray systemRoot = qgetenv("SYSTEMROOT");
|
if (!copy.contains(rootKey)) {
|
||||||
|
QByteArray systemRoot = qgetenv("SystemRoot");
|
||||||
if (!systemRoot.isEmpty())
|
if (!systemRoot.isEmpty())
|
||||||
copy.insert(QLatin1String("SYSTEMROOT"), QString::fromLocal8Bit(systemRoot));
|
copy.insert(rootKey, QString::fromLocal8Bit(systemRoot));
|
||||||
}
|
}
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
@ -43,10 +43,6 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
|
||||||
// Note:
|
|
||||||
// in cross-platform tests, ALWAYS use UPPERCASE variable names
|
|
||||||
// That's because on Windows, the variables are uppercased
|
|
||||||
|
|
||||||
class tst_QProcessEnvironment: public QObject
|
class tst_QProcessEnvironment: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -214,7 +210,7 @@ void tst_QProcessEnvironment::caseSensitivity()
|
|||||||
e.insert("foo", "bar");
|
e.insert("foo", "bar");
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// on Windows, it's uppercased
|
// Windows is case-insensitive, but case-preserving
|
||||||
QVERIFY(e.contains("foo"));
|
QVERIFY(e.contains("foo"));
|
||||||
QVERIFY(e.contains("FOO"));
|
QVERIFY(e.contains("FOO"));
|
||||||
QVERIFY(e.contains("FoO"));
|
QVERIFY(e.contains("FoO"));
|
||||||
@ -223,8 +219,12 @@ void tst_QProcessEnvironment::caseSensitivity()
|
|||||||
QCOMPARE(e.value("FOO"), QString("bar"));
|
QCOMPARE(e.value("FOO"), QString("bar"));
|
||||||
QCOMPARE(e.value("FoO"), QString("bar"));
|
QCOMPARE(e.value("FoO"), QString("bar"));
|
||||||
|
|
||||||
|
// Per Windows, this overwrites the value, but keeps the name's original capitalization
|
||||||
|
e.insert("Foo", "Bar");
|
||||||
|
|
||||||
QStringList list = e.toStringList();
|
QStringList list = e.toStringList();
|
||||||
QCOMPARE(list.at(0), QString("FOO=bar"));
|
QCOMPARE(list.length(), 1);
|
||||||
|
QCOMPARE(list.at(0), QString("foo=Bar"));
|
||||||
#else
|
#else
|
||||||
// otherwise, it's case sensitive
|
// otherwise, it's case sensitive
|
||||||
QVERIFY(e.contains("foo"));
|
QVERIFY(e.contains("foo"));
|
||||||
@ -236,6 +236,7 @@ void tst_QProcessEnvironment::caseSensitivity()
|
|||||||
QCOMPARE(e.value("foo"), QString("bar"));
|
QCOMPARE(e.value("foo"), QString("bar"));
|
||||||
|
|
||||||
QStringList list = e.toStringList();
|
QStringList list = e.toStringList();
|
||||||
|
QCOMPARE(list.length(), 2);
|
||||||
QVERIFY(list.contains("foo=bar"));
|
QVERIFY(list.contains("foo=bar"));
|
||||||
QVERIFY(list.contains("FOO=baz"));
|
QVERIFY(list.contains("FOO=baz"));
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user