[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: kpf breaks on non-latin1 characters
From: Jakub Stachowski <stachowski () hypair ! net>
Date: 2004-12-10 18:19:58
Message-ID: 200412101919.58678.stachowski () hypair ! net
[Download RAW message or body]
Hello,
I get 404 error when trying to download file with name containing non-latin1
characters from directory shared using kpf. Attached patch fixes that for me
by replacing hand-made encoding/decoding functions with those from KURL, but
I would be very grateful for someone else to test it too. Just put file with
weird characters into directory, share it using "public file server" kicker
applet and try to download this file.
["nonlatin.patch" (text/x-diff)]
diff -u -p -u -r1.10 DirectoryLister.cpp
--- src/DirectoryLister.cpp 31 Aug 2003 02:01:21 -0000 1.10
+++ src/DirectoryLister.cpp 10 Dec 2004 18:12:58 -0000
@@ -300,9 +300,10 @@ namespace KPF
QString item_class = QString((fi->isDir()) ? "direntry" : "fileentry");
+ KURL fu(path+fi->fileName());
html +=
"<a href=\""
- + quote(path + fi->fileName())
+ + fu.encodedPathAndQuery()
+ (fi->isDir() ? "/" : "")
+ "\" class=\""
+ item_class
Index: src/Request.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kpf/src/Request.cpp,v
retrieving revision 1.9
diff -u -p -u -r1.9 Request.cpp
--- src/Request.cpp 20 Nov 2002 20:44:55 -0000 1.9
+++ src/Request.cpp 10 Dec 2004 18:12:58 -0000
@@ -150,7 +150,8 @@ namespace KPF
void
Request::setPath(const QString & s)
{
- path_ = clean(unquote(s));
+ KURL p(s);
+ path_ = clean(p.path());
#if 0
if ('/' == path_.at(path_.length() - 1))
Index: src/Utils.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kpf/src/Utils.cpp,v
retrieving revision 1.13
diff -u -p -u -r1.13 Utils.cpp
--- src/Utils.cpp 31 Oct 2004 04:34:09 -0000 1.13
+++ src/Utils.cpp 10 Dec 2004 18:12:58 -0000
@@ -407,124 +407,6 @@ namespace KPF
return s;
}
- QString
- unquote(const QString & quoted)
- {
- if (quoted.length() < 3)
- return quoted;
-
- QString unquoted;
-
- uint i;
- for (i = 0; i < quoted.length() - 2; ++i)
- {
- if ('%' == quoted[i])
- {
- // First character.
-
- char hexChar = quoted[i + 1].lower().latin1();
-
- char unquotedChar = '\0';
-
- if (hexChar >= '0' && hexChar <= '9')
- {
- unquotedChar = 16 * (hexChar - '0');
- }
- else if (hexChar >= 'a' && hexChar <= 'f')
- {
- unquotedChar = 16 * (hexChar - 'a' + 10);
- }
- else
- {
- kpfDebug << "Bad hex encoding in quoted string" << endl;
- unquotedChar = hexChar;
- }
-
- // Second character.
-
- hexChar = quoted[i + 2].lower().latin1();
-
- if (hexChar >= '0' && hexChar <= '9')
- {
- unquotedChar += hexChar - '0';
- }
- else if (hexChar >= 'a' && hexChar <= 'f')
- {
- unquotedChar += hexChar - 'a' + 10;
- }
- else
- {
- kpfDebug << "Bad hex encoding in quoted string" << endl;
- unquotedChar = hexChar;
- }
-
- unquoted += unquotedChar;
-
- // Skip past the characters we just used.
-
- i += 2;
- }
- else
- {
- unquoted += quoted[i];
- }
- }
-
- for (; i < quoted.length(); ++i)
- {
- if ('%' == quoted[i])
- {
- kpfDebug << "Bogus % in quoted string" << endl;
- //return QString::null;
- }
-
- unquoted += quoted[i];
- }
-
- return unquoted;
- }
-
- QString
- quote(const QString & unquoted)
- {
- QString quoted;
-
- for (uint i = 0; i < unquoted.length(); ++i)
- {
- char c = unquoted[i];
-
- if (
- (c >= 'a' && c <= 'z')
- ||
- (c >= 'A' && c <= 'Z')
- ||
- (c >= '0' && c <= '9')
- ||
- ('.' == c)
- ||
- (':' == c)
- ||
- ('_' == c)
- ||
- ('-' == c)
- ||
- ('/' == c)
- ||
- ('?' == c)
- ||
- ('+' == c)
- )
- {
- quoted += c;
- }
- else
- {
- quoted += QString("%%1").arg(uchar(c), 0, 16);
- }
- }
-
- return quoted;
- }
} // End namespace KPF
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic