[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: URL-completion bug (patch)
From:       David Smith <dsmith () algonet ! se>
Date:       2000-10-08 10:27:28
[Download RAW message or body]

Dawit Alemayehu wrote:
> 
> On Sat, 07 Oct 2000, David Smith wrote:
> > Dawit Alemayehu wrote:
> > > On Fri, 06 Oct 2000, Carsten Pfeiffer wrote:
> > > > On Fri, Oct 06, 2000 at 02:13:32AM -0400, Dawit Alemayehu wrote:
> > > >
> > > > Hiya,
> > > >
> > > > > On Thu, 05 Oct 2000, David Faure wrote:
> > > > > > When it completes a directory name with a space, it puts
> > > > > > double-quotes around the full path, like:  "/blah/dir with space"/
> > > > > >
> > > > > > That's probably fine in a shell, but it breaks in konqueror....
> > > > > > (it fires up an ikws search !)
> > > > > >
> > > > > > Should konqueror be fixed, or should KURLCompletion be fixed ?
> > > > >
> > > > > Well it can be fixed at either place I guess, but the correct palce
> > > > > seems to me to be KURLCompletion itself.  The culprit here is the
> > > >
> > > > exactly.
> > > >
> > > > > KURLCompletion::postProcessMatch function which invokes
> > > > > quoteText(...) on the matched text.  IMHO, this code belongs in
> > > > > KShellCompletion and not KURLCompletion, but I did not make the
> > > > > change since I do not know why it was put there in the first place.
> > > > > Carsten do you know ?
> > > >
> > > > No, I don't know either, but probably David Smith knows?
> > >
> > > Okay I am forwarding this to him then.  Any inputs on the above matter
> > > David?
> >
> > You're quite right.  The quotation should be made in KShellCompletion.
> > It made sense to have it in KURLCompletion when I wrote it, but not
> > now.
> > Should I make the change (at this moment)?
> 
> Yes please.  But ofcourse you have to send a patch here to get approval
> before you commit.
> 

This patch moves quoteText() and unquote() from KURLCompletion
to KShellCompletion.

/David
["kshellcompletion.cpp.diff" (text/plain)]

Index: kshellcompletion.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kshellcompletion.cpp,v
retrieving revision 1.1
diff -u -r1.1 kshellcompletion.cpp
--- kshellcompletion.cpp	2000/03/30 01:09:00	1.1
+++ kshellcompletion.cpp	2000/10/08 10:06:41
@@ -48,8 +48,10 @@
 	//
 	splitText(text, m_text_start, m_text_compl);
 	
-	//kDebugInfo("KShellCompletion: split: '%s' - '%s'", 
-	//	m_text_start.latin1(), m_text_compl.latin1());
+	// Remove quotes from the text to be completed
+	//
+	QString tmp = unquote(m_text_compl);
+	m_text_compl = tmp;
 
 	// Do exe-completion if there was no unquoted space
 	//
@@ -77,6 +79,7 @@
  * Called by KCompletion before emitting match() and matches()
  *
  * Add add the part of the text that was not completed
+ * Add quotes when needed 
  */
 void KShellCompletion::postProcessMatch( QString *match )
 {
@@ -88,6 +91,11 @@
 	if ( *match == QString::null )
 		return;
 		
+	if ( match->right(1) == QChar('/') )
+		quoteText( match, false, true ); // don't quote the trailing '/'
+	else
+		quoteText( match, false, false ); // quote the whole text
+	
 	match->prepend( m_text_start );
 
 	//kDebugInfo("KShellCompletion::postProcessMatch() ut: '%s'",
@@ -101,8 +109,14 @@
 	for ( QStringList::Iterator it = matches->begin();
 		  it != matches->end(); it++ )
 	{
-		if ( (*it) != QString::null ) 
+		if ( (*it) != QString::null ) {
+			if ( (*it).right(1) == QChar('/') )
+				quoteText( &(*it), false, true ); // don't quote trailing '/'
+			else
+				quoteText( &(*it), false, false ); // quote the whole text
+
 			(*it).prepend( m_text_start );
+		}
 	}
 }
 
@@ -171,6 +185,105 @@
 	//kDebugInfo("split right = '%s'", text_compl.latin1());
 }
 
+/*
+ * quoteText()
+ *
+ * Add quotations to 'text' if needed or if 'force' = true
+ * Returns true if quotes were added
+ *
+ * skip_last => ignore the last charachter (we add a space or '/' to all filenames)
+ */
+bool KShellCompletion::quoteText(QString *text, bool force, bool skip_last)
+{
+	int pos;
+
+	if ( !force ) {
+		pos = text->find( m_word_break_char );
+		if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
+	}
+
+	if ( !force && pos == -1 ) {
+		pos = text->find( m_quote_char1 );
+		if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
+	}
+
+	if ( !force && pos == -1 ) {
+		pos = text->find( m_quote_char2 );
+		if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
+	}
+
+	if ( !force && pos == -1 ) {
+		pos = text->find( m_escape_char );
+		if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
+	}
+
+	if ( force || (pos >= 0) ) {
+
+		// Escape \ in the string
+		text->replace( QRegExp( m_escape_char ),
+		               QString( m_escape_char ) + m_escape_char );
+
+		// Escape " in the string
+		text->replace( QRegExp( m_quote_char1 ),
+		               QString( m_escape_char ) + m_quote_char1 );
+
+		// " at the beginning
+		text->insert( 0, m_quote_char1 );
+
+		// " at the end
+		if ( skip_last )
+			text->insert( text->length()-1, m_quote_char1 );
+		else
+			text->insert( text->length(), m_quote_char1 );
+
+		return true;
+	}
+
+	return false;
+}
+ 
+/*
+ * unquote
+ *
+ * Remove quotes and return the result in a new string
+ *
+ */
+QString KShellCompletion::unquote(const QString &text)
+{
+	bool in_quote = false;
+	bool escaped = false;
+	QChar p_last_quote_char;
+	QString result;
+
+	for (uint pos = 0; pos < text.length(); pos++) {
+
+		if ( escaped ) {
+			escaped = false;
+			result.insert( result.length(), text[pos] );
+		}
+		else if ( in_quote && text[pos] == p_last_quote_char ) {
+			in_quote = false;
+		}
+		else if ( !in_quote && text[pos] == m_quote_char1 ) {
+			p_last_quote_char = m_quote_char1;
+			in_quote = true;
+		}
+		else if ( !in_quote && text[pos] == m_quote_char2 ) {
+			p_last_quote_char = m_quote_char2;
+			in_quote = true;
+		}
+		else if ( text[pos] == m_escape_char ) {
+			escaped = true;
+			result.insert( result.length(), text[pos] );
+		}
+		else {
+			result.insert( result.length(), text[pos] );
+		}
+
+	}
+
+	return result;
+}
 
 #include "kshellcompletion.moc"
 



["kshellcompletion.h.diff" (text/plain)]

Index: kshellcompletion.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kshellcompletion.h,v
retrieving revision 1.1
diff -u -r1.1 kshellcompletion.h
--- kshellcompletion.h	2000/03/30 01:09:01	1.1
+++ kshellcompletion.h	2000/10/08 10:06:27
@@ -59,6 +59,10 @@
 private:
 	// Find the part of text that should be completed
 	void splitText(const QString &text, QString &text_start, QString &text_compl);
+	// Insert quotes and neseccary escapes
+	bool quoteText(QString *text, bool force, bool skip_last);
+	QString unquote(const QString &text);
+		                                                                        
 	QString m_text_start; // part of the text that was not completed
 	QString m_text_compl; // part of the text that was completed (unchanged)
 



["kurlcompletion.cpp.diff" (text/plain)]

Index: kurlcompletion.cpp
===================================================================
RCS file: /home/kde/kdelibs/kio/kurlcompletion.cpp,v
retrieving revision 1.14
diff -u -r1.14 kurlcompletion.cpp
--- kurlcompletion.cpp	2000/09/18 23:08:51	1.14
+++ kurlcompletion.cpp	2000/10/08 10:06:59
@@ -94,9 +94,7 @@
         // we then might restart the same job again
 
 
-        // Remove quotes from the text
-        //
-        QString text_copy = unquote(text);
+		QString text_copy = text;
 
         // This is a bad hack to make it work with file: URLs
         // Please, let me find time to fix this up later...
@@ -391,82 +389,14 @@
  *
  * Called by KCompletion before emitting match() and matches()
  *
- * Add quotes when needed and add the part of the text that
- * was not completed
+ * These are just empty functions now, can they be removed?
  */
-void KURLCompletion::postProcessMatch( QString *match )
+void KURLCompletion::postProcessMatch( QString * /*match*/ )
 {
-        //kdDebug() "KURLCompletion::postProcessMatch() -- in: " << *match << endl;
-
-        if ( *match == QString::null )
-                return;
-
-        if ( match->right(1) == QChar('/') )
-                quoteText( match, false, true ); // don't quote the trailing '/'
-        else
-                quoteText( match, false, false ); // quote the whole text
-
-        //kdDebug() << "KURLCompletion::postProcessMatch() -- ut: " << *match << endl;
 }
 
-void KURLCompletion::postProcessMatches( QStringList *matches )
-{
-        //kDebugInfo("KURLCompletion::postProcessMatches()");
-
-        for ( QStringList::Iterator it = matches->begin();
-                  it != matches->end(); it++ )
-        {
-                if ( (*it) != QString::null ) {
-
-                        if ( (*it).right(1) == QChar('/') )
-                                quoteText( &(*it), false, true ); // don't quote trailing '/'
-                        else
-                                quoteText( &(*it), false, false ); // quote the whole text
-                }
-        }
-}
-
-/*
- * unquote
- *
- * Remove quotes and return the result in a new string
- *
- */
-QString KURLCompletion::unquote(const QString &text)
+void KURLCompletion::postProcessMatches( QStringList * /*matches*/ )
 {
-        bool in_quote = false;
-        bool escaped = false;
-        QChar p_last_quote_char;
-        QString result;
-
-        for (uint pos = 0; pos < text.length(); pos++) {
-
-                if ( escaped ) {
-                        escaped = false;
-                        result.insert( result.length(), text[pos] );
-                }
-                else if ( in_quote && text[pos] == p_last_quote_char ) {
-                        in_quote = false;
-                }
-                else if ( !in_quote && text[pos] == m_quote_char1 ) {
-                        p_last_quote_char = m_quote_char1;
-                        in_quote = true;
-                }
-                else if ( !in_quote && text[pos] == m_quote_char2 ) {
-                        p_last_quote_char = m_quote_char2;
-                        in_quote = true;
-                }
-                else if ( text[pos] == m_escape_char ) {
-                        escaped = true;
-                        result.insert( result.length(), text[pos] );
-                }
-                else {
-                        result.insert( result.length(), text[pos] );
-                }
-
-        }
-
-        return result;
 }
 
 /*
@@ -547,63 +477,6 @@
 
         (void) closedir( dp );
 
-}
-
-/*
- * quoteText()
- *
- * Add quotations to 'text' if needed or if 'force' = true
- * Returns true if quotes were added
- *
- * skip_last => ignore the last charachter (we add a space or '/' to all filenames)
- */
-bool KURLCompletion::quoteText(QString *text, bool force, bool skip_last)
-{
-        int pos;
-
-        if ( !force ) {
-                pos = text->find( m_word_break_char );
-                if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
-        }
-
-        if ( !force && pos == -1 ) {
-                pos = text->find( m_quote_char1 );
-                if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
-        }
-
-        if ( !force && pos == -1 ) {
-                pos = text->find( m_quote_char2 );
-                if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
-        }
-
-        if ( !force && pos == -1 ) {
-                pos = text->find( m_escape_char );
-                if ( skip_last && (pos == (int)(text->length())-1) ) pos = -1;
-        }
-
-        if ( force || (pos >= 0) ) {
-
-                // Escape \ in the string
-                text->replace( QRegExp( m_escape_char ),
-                                          QString( m_escape_char ) + m_escape_char );
-
-                // Escape " in the string
-                text->replace( QRegExp( m_quote_char1 ),
-                                          QString( m_escape_char ) + m_quote_char1 );
-
-                // " at the beginning
-                text->insert( 0, m_quote_char1 );
-
-                // " at the end
-                if ( skip_last )
-                        text->insert( text->length()-1, m_quote_char1 );
-                else
-                        text->insert( text->length(), m_quote_char1 );
-
-                return true;
-        }
-
-        return false;
 }
 
 /*



["kurlcompletion.h.diff" (text/plain)]

Index: kurlcompletion.h
===================================================================
RCS file: /home/kde/kdelibs/kio/kurlcompletion.h,v
retrieving revision 1.8
diff -u -r1.8 kurlcompletion.h
--- kurlcompletion.h	2000/08/22 16:30:20	1.8
+++ kurlcompletion.h	2000/10/08 10:07:13
@@ -171,11 +171,7 @@
 
 	KURL *m_current_url; // the url beeing listed by KIO
 
-	// Insert quotes and neseccary escapes
-	bool quoteText(QString *text, bool force, bool skip_last);
-	
 	// Remove quotes/escapes
-	QString unquote(const QString &text);
 	QString unescape(const QString &text);
 
 	QChar m_word_break_char;




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic