Environment: Disable escaping when expanding variables

This breaks too much on windows.

Reviewed-by: dt
This commit is contained in:
Tobias Hunger
2010-10-06 16:11:07 +02:00
parent f3dfc8915d
commit ad008b9b57
3 changed files with 7 additions and 25 deletions

View File

@@ -373,20 +373,15 @@ QString Environment::joinArgumentList(const QStringList &arguments)
return result; return result;
} }
enum State { BASE, VARIABLE, OPTIONALVARIABLEBRACE, STRING, STRING_ESCAPE, ESCAPE }; enum State { BASE, VARIABLE, OPTIONALVARIABLEBRACE, STRING };
/** Expand environment variables in a string. /** Expand environment variables in a string.
* *
* Environment variables are accepted in the following forms: * Environment variables are accepted in the following forms:
* $SOMEVAR, ${SOMEVAR} and %SOMEVAR%. * $SOMEVAR, ${SOMEVAR} and %SOMEVAR%.
* *
* The following escape sequences are supported:
* "\$", "\\" and "\"" which will be replaced by '$', '\' and '%'
* respectively.
*
* Strings enclosed in '"' characters do not get varaibles * Strings enclosed in '"' characters do not get varaibles
* substituted. Escape codes are processed though. * substituted.
*
*/ */
QString Environment::expandVariables(const QString &input) const QString Environment::expandVariables(const QString &input) const
{ {
@@ -399,9 +394,7 @@ QString Environment::expandVariables(const QString &input) const
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
QChar c = input.at(i); QChar c = input.at(i);
if (state == BASE) { if (state == BASE) {
if (c == '\\') { if (c == '$') {
state = ESCAPE;
} else if (c == '$') {
state = OPTIONALVARIABLEBRACE; state = OPTIONALVARIABLEBRACE;
variable.clear(); variable.clear();
endVariable = QChar(0); endVariable = QChar(0);
@@ -433,20 +426,12 @@ QString Environment::expandVariables(const QString &input) const
variable = c; variable = c;
state = VARIABLE; state = VARIABLE;
} else if (state == STRING) { } else if (state == STRING) {
if (c == '\\') { if (c == '\"') {
state = STRING_ESCAPE;
} else if (c == '\"') {
state = BASE; state = BASE;
result += c; result += c;
} else { } else {
result += c; result += c;
} }
} else if (state == STRING_ESCAPE) {
result += c;
state = STRING;
} else if (state == ESCAPE){
result += c;
state = BASE;
} }
} }
if (state == VARIABLE) if (state == VARIABLE)

View File

@@ -110,9 +110,7 @@ QString PathChooserPrivate::expandedPath(const QString &input) const
{ {
if (input.isEmpty()) if (input.isEmpty())
return input; return input;
// Environment does \-expansion, too. const QString path = QDir::fromNativeSeparators(m_environment.expandVariables(input));
const QString nativeInput = QDir::fromNativeSeparators(input);
const QString path = QDir::fromNativeSeparators(m_environment.expandVariables(nativeInput));
if (path.isEmpty()) if (path.isEmpty())
return path; return path;

View File

@@ -151,13 +151,12 @@ void AbstractProcessStep::run(QFutureInterface<bool> &fi)
fi.reportResult(true); fi.reportResult(true);
return; return;
} }
QString workDir = m_environment.expandVariables(m_workingDirectory); QDir wd(m_environment.expandVariables(m_workingDirectory));
QDir wd(workDir);
if (!wd.exists()) if (!wd.exists())
wd.mkpath(wd.absolutePath()); wd.mkpath(wd.absolutePath());
m_process = new QProcess(); m_process = new QProcess();
m_process->setWorkingDirectory(workDir); m_process->setWorkingDirectory(wd.absolutePath());
m_process->setEnvironment(m_environment.toStringList()); m_process->setEnvironment(m_environment.toStringList());
connect(m_process, SIGNAL(readyReadStandardOutput()), connect(m_process, SIGNAL(readyReadStandardOutput()),