From 29ef5bd1437caf8afbc81e26da54d0f52c7d6963 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 8 Apr 2012 19:13:18 +0200 Subject: [PATCH] Thumbnails: need to url_encode the source path before hashing for thumbnail name --- src/qtgui/reslist.cpp | 7 ++++ src/utils/pathut.cpp | 76 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/src/qtgui/reslist.cpp b/src/qtgui/reslist.cpp index bc06cf2f..18215e71 100644 --- a/src/qtgui/reslist.cpp +++ b/src/qtgui/reslist.cpp @@ -231,9 +231,16 @@ string QtGuiResListPager::iconUrl(RclConfig *config, Rcl::Doc& doc) ConfIndexer::docsToPaths(docs, paths); if (!paths.empty()) { string path; + LOGDEB2(("ResList::iconUrl: source path [%s]\n", paths[0].c_str())); if (thumbPathForUrl(cstr_fileu + paths[0], 128, path)) { + LOGDEB2(("ResList::iconUrl: icon path [%s]\n", path.c_str())); return cstr_fileu + path; + } else { + LOGDEB2(("ResList::iconUrl: no icon: path [%s]\n", + path.c_str())); } + } else { + LOGDEB(("ResList::iconUrl: docsToPaths failed\n")); } } return ResListPager::iconUrl(config, doc); diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 8b4c59fd..65f406a0 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -389,6 +389,52 @@ bool path_isdir(const string& path) return false; } +// Allowed punctuation in the path part of an URI according to RFC2396 +// -_.!~*'():@&=+$, +/* +21 ! + 22 " + 23 # +24 $ + 25 % +26 & +27 ' +28 ( +29 ) +2A * +2B + +2C , +2D - +2E . +2F / +30 0 +... +39 9 +3A : + 3B ; + 3C < +3D = + 3E > + 3F ? +40 @ +41 A +... +5A Z + 5B [ + 5C \ + 5D ] + 5E ^ +5F _ + 60 ` +61 a +... +7A z + 7B { + 7C | + 7D } +7E ~ + 7F DEL +*/ string url_encode(const string& url, string::size_type offs) { string out = url.substr(0, offs); @@ -397,24 +443,23 @@ string url_encode(const string& url, string::size_type offs) int c; const char *h = "0123456789ABCDEF"; c = cp[i]; - if(c <= 0x1f || + if (c <= 0x20 || c >= 0x7f || - c == '<' || - c == '>' || - c == ' ' || - c == '\t'|| c == '"' || c == '#' || c == '%' || - c == '{' || - c == '}' || - c == '|' || - c == '\\' || - c == '^' || - c == '~'|| + c == ';' || + c == '<' || + c == '>' || + c == '?' || c == '[' || + c == '\\' || c == ']' || - c == '`') { + c == '^' || + c == '`' || + c == '{' || + c == '|' || + c == '}' ) { out += '%'; out += h[(c >> 4) & 0xf]; out += h[c & 0xf]; @@ -445,7 +490,9 @@ string url_gpath(const string& url) return path_canon(url.substr(colon+1)); } -// Convert to file path if url is like file:// +// Convert to file path if url is like file: +// Note: this only works with our internal pseudo-urls which are not +// encoded/escaped string fileurltolocalpath(string url) { if (url.find("file://") == 0) @@ -570,7 +617,8 @@ static const string thmbdirnormal = ".thumbnails/normal"; static void thumbname(const string& url, string& name) { string digest; - MD5String(url, digest); + string l_url = url_encode(url); + MD5String(l_url, digest); MD5HexPrint(digest, name); name += ".png"; }