aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2010-10-10 15:15:54 +0000
committerGravatar Szymon Tomasz Stefanek2010-10-10 15:15:54 +0000
commit448c2faed6e47ffd1253c5403f2386d5930c178d (patch)
treee80996a9e279dbe55068175e36aec028d57d1416
parentThe two examples were a bit misleading, need to think of better ones. (diff)
downloadKVIrc-448c2faed6e47ffd1253c5403f2386d5930c178d.tar.gz
KVIrc-448c2faed6e47ffd1253c5403f2386d5930c178d.tar.bz2
KVIrc-448c2faed6e47ffd1253c5403f2386d5930c178d.zip
Escape better completed nicknames and channel names
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5055 17fca916-40b9-46aa-a4ea-0a15b648b75c
-rw-r--r--src/kvirc/ui/kvi_input_editor.cpp34
-rw-r--r--src/kvirc/ui/kvi_input_editor.h1
2 files changed, 26 insertions, 9 deletions
diff --git a/src/kvirc/ui/kvi_input_editor.cpp b/src/kvirc/ui/kvi_input_editor.cpp
index dbf6f027e..6f7d8d67d 100644
--- a/src/kvirc/ui/kvi_input_editor.cpp
+++ b/src/kvirc/ui/kvi_input_editor.cpp
@@ -1412,6 +1412,7 @@ void KviInputEditor::keyReleaseEvent(QKeyEvent * e)
e->ignore();
}
+
void KviInputEditor::getWordBeforeCursor(QString & szBuffer, bool * bIsFirstWordInLine)
{
if(m_szTextBuffer.isEmpty() || m_iCursorPosition <= 0)
@@ -1434,6 +1435,18 @@ void KviInputEditor::getWordBeforeCursor(QString & szBuffer, bool * bIsFirstWord
else *bIsFirstWordInLine = true;
}
+void KviInputEditor::completionEscapeUnsafeToken(QString &szToken)
+{
+ szToken.replace("\\","\\\\");
+ szToken.replace(";","\\;");
+ szToken.replace("$","\\$");
+ szToken.replace("%","\\%");
+ szToken.replace("\"","\\\"");
+ szToken.replace(" ","\\ ");
+}
+
+
+
void KviInputEditor::completion(bool bShift)
{
// FIXME: Spaces in directory completion can mess everything completely
@@ -1480,6 +1493,7 @@ void KviInputEditor::completion(bool bShift)
szWord.remove(0,2-iOffset);
if(szWord.isEmpty()) return;
KviKvsKernel::instance()->completeFunction(szWord,&tmp);
+ // function names don't need to be escaped
bIsFunction = true;
}
else if(bFirstWordInLine || iOffset)
@@ -1488,6 +1502,7 @@ void KviInputEditor::completion(bool bShift)
szWord.remove(0,1-iOffset);
if(szWord.isEmpty())return;
KviKvsKernel::instance()->completeCommand(szWord,&tmp);
+ // commands don't need to be escaped
bIsCommand = true;
} else {
// directory completion attempt
@@ -1508,14 +1523,14 @@ void KviInputEditor::completion(bool bShift)
if( (szWord.length()==1) && (m_pKviWindow->windowName()[0].unicode()==uc))
{
szMatch=m_pKviWindow->windowName();
+ completionEscapeUnsafeToken(szMatch);
szMatch.append(" ");
replaceWordBeforeCursor(szWord,szMatch,false);
repaintWithCursorOn();
return;
- } else {
- if(m_pKviWindow->console())
- m_pKviWindow->console()->completeChannel(szWord,&tmp);
}
+ if(m_pKviWindow->console())
+ m_pKviWindow->console()->completeChannel(szWord,&tmp);
}
//FIXME: Complete also on irc:// starting strings, not only irc.?
@@ -1570,11 +1585,12 @@ void KviInputEditor::completion(bool bShift)
if(bFirstWordInLine || (!KVI_OPTION_BOOL(KviOption_boolUseNickCompletionPostfixForFirstWordOnly)))
szMatch.append(KVI_OPTION_STRING(KviOption_stringNickCompletionPostfix));
}
- if(bInCommand)
- {
- // escape crazy things like Nick\nquit
- szMatch.replace(QChar('\\'),QString::fromAscii("\\\\"));
- }
+ }
+
+ if(bInCommand)
+ {
+ // escape crazy things like Nick\nquit
+ completionEscapeUnsafeToken(szMatch);
}
} else {
QString szAll;
@@ -1640,7 +1656,7 @@ void KviInputEditor::standardNickCompletionInsertCompletedText(const QString &sz
if(bInCommand)
{
// escape crazy things like Nick\nquit
- szBuffer.replace(QChar('\\'),QString::fromAscii("\\\\"));
+ completionEscapeUnsafeToken(szBuffer);
}
replaceWordBeforeCursor(szReplacedWord,szBuffer,false);
}
diff --git a/src/kvirc/ui/kvi_input_editor.h b/src/kvirc/ui/kvi_input_editor.h
index d6aa4a7b4..09d77a394 100644
--- a/src/kvirc/ui/kvi_input_editor.h
+++ b/src/kvirc/ui/kvi_input_editor.h
@@ -815,6 +815,7 @@ private slots:
*/
void dummy();
protected:
+ void completionEscapeUnsafeToken(QString &szToken);
void installShortcuts();
virtual void drawContents(QPainter *);
//virtual void resizeEvent(QResizeEvent * e);