PATCH: kdelibs/kdecore/kstringhandler.cpp tagURLs() method

Scott Wheeler wheeler at kde.org
Wed Jul 10 08:57:38 BST 2002


I talked for a while with Stephan (aka \sh) on IRC today about this.  But 
since I don't know this code at all (and the regexp scared me :-) ) I thought 
it best to post it here.  Please let me know if this is ok to commit.

Cheers,

-Scott

----------  Forwarded Message  ----------
Date: Wednesday 10 July 2002 3:52
From: Stephan Hermann <sh at kde-coder.de>
To: wheeler at kde.org

Good Morning,

I just found this method in the actual kdelibs cvs tree, and checked it, 
because I was in need of this function.
After playing with it a little bit, I found a logical mistake in it.

Example:

if someone has a string like this:

	>>Hey, take a look at www.kde.org<<

and passes it to KStringHandler::tagURLs(), this method will find 

	>>www.kde.org<< 

and replaces it with 
	>> <a href="www.kde.org">www.kde.org</a> <<

But if you use this href in conjunction with QTextBrowser or KTextBrowser 
there is a problem:

If your default browser is konqueror for example, konqueror will fire up and 
tries to fetch this url:

	>> file:///<your homedir>/www.kde.org

and that is a mistake. After all, www.kde.org is a malformed URL.

My patch will "fix" this.

First, it's checking not only for 

	>>www.<< 

, it checks for 

	>>ftp.<< 

too.

If the new RegExp matches www. or ftp. it will insert 
	>> http:// << (matched www.)
or
	>> ftp:// << (matched ftp.) 
to the href.
If the string has a transfer protocol (aka not a malformed URL) ;)
there is nothing to do for it.

After all I made the QRegExp a little bit more "perl"ish, and escaped some 
"could be trouble making" characters.

Please commit this patch to the actual cvs tree of kdelibs if you determine 
the need of this patch.

Thanks,

\sh

PS: thanks to wheeler at kde.org for his help :)

- -- 
St. Hermann, Troisdorf
One solution for a simple problem: A7 B4 C2 D5 E8 F1 G3 H6

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kstringhandler.cpp.patch
Type: text/x-diff
Size: 1512 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20020710/20887381/attachment.patch>


More information about the kde-core-devel mailing list