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

List:       kfm-devel
Subject:    PATCH: KonqRun::askSave and URLs containing '%'
From:       Maarten ter Huurne <mth () stack ! nl>
Date:       2001-08-23 22:30:01
[Download RAW message or body]

Hi,

Below is a patch for Konqueror from KDE 2.2, which fixes a problem in 
KonqRun::askSave. The string displayed was created using the following code:
  i18n("Open '%1' using '%2'?").arg( surl ).arg(offer->name())
This fails when surl contains %1 or %2 as substrings. This happens for 
example with URLs that contain escaped space characters (%20). The result is 
messages like "Open 'someXMMS0songs.m3u' using '%2'?".

This is my first patch contribution to KDE, so please review it carefully.

Bye,
		Maarten

274a275,299
> /* An alternative to QString::arg.
>    This function works correctly when multiple strings are substituted
>    which can contain '%digit' codes themselves.
>    Note: the usage differs slightly from QString::arg:
>    this function requires the arguments to be numbered 1, 2, 3 etc,
>    with '%n' corresponding to index n - 1 in the args list.
> */
> static QString safeArg(const QString &s, const QStringList &args)
> {
>     int i = 0, j;
>     QString ret;
>     while ((j = s.find('%', i)) != -1) {
>         ret += s.mid(i, j - i);
>         j++; // skip '%'
>         i = j;
>         while (s[j].isDigit()) j++;
>         int n = s.mid(i, j - i).toInt();
>         i = j;
>         if (n > 0 && n <= args.count()) ret += args[n - 1];
>         else kdError(1202) << "safeArg: argument index " << n << " out of 
range" << endl;
>     }
>     ret += s.mid(i);
>     return ret;
> }
>
279,281c304,310
<     QString question = offer ? i18n("Open '%1' using '%2'?").
<                                arg( surl ).arg(offer->name())
<                        : i18n("Open '%1' ?").arg( surl );
---
>     QString question;
>     if (offer) {
>         QStringList args(surl);
>         args.append(offer->name());
>         question = safeArg( i18n("Open '%1' using '%2'?"), args);
>     }
>     else question = i18n("Open '%1' ?").arg( surl );

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

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