Solving issue 1650: "Image information not displayed when dir has & in name"

This commit is contained in:
natureh 510
2013-01-01 17:18:44 +01:00
parent ba1d301412
commit 48d5fa06a3
3 changed files with 34 additions and 2 deletions

View File

@@ -705,8 +705,8 @@ void EditorPanel::info_toggled () {
} }
infoString3 = Glib::ustring::compose ("<span size=\"small\">%1</span><span>%2</span>", infoString3 = Glib::ustring::compose ("<span size=\"small\">%1</span><span>%2</span>",
Glib::path_get_dirname(openThm->getFileName()) + G_DIR_SEPARATOR_S, escapeHtmlChars(Glib::path_get_dirname(openThm->getFileName())) + G_DIR_SEPARATOR_S,
Glib::path_get_basename(openThm->getFileName())); escapeHtmlChars(Glib::path_get_basename(openThm->getFileName())) );
infoString = Glib::ustring::compose ("%1\n%2\n%3",infoString1, infoString2, infoString3); infoString = Glib::ustring::compose ("%1\n%2\n%3",infoString1, infoString2, infoString3);
} }

View File

@@ -28,6 +28,37 @@
using namespace std; using namespace std;
Glib::ustring escapeHtmlChars(const Glib::ustring &src) {
// Sources chars to be escaped
static const Glib::ustring srcChar("&<>");
// Destination strings, in the same order than the source
static std::vector<Glib::ustring> dstChar(3);
dstChar.at(0) = "&amp;";
dstChar.at(1) = "&lt;";
dstChar.at(2) = "&gt;";
// Copying the original string, that will be modified
Glib::ustring dst(src);
// Iterating all chars of the copy of the source string
for (size_t i=0; i<dst.length();) {
// Looking out if it's part of the characters to be escaped
size_t pos = srcChar.find_first_of(dst.at(i), 0);
if (pos != Glib::ustring::npos) {
// If yes, replacing the char in the destination string
dst.replace(i, 1, dstChar.at(pos));
// ... and going forward by the length of the new string
i += dstChar.at(pos).length();
}
else ++i;
}
return dst;
}
bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference) { bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference) {
Glib::ListHandle<Gtk::Widget*> list = cont->get_children (); Glib::ListHandle<Gtk::Widget*> list = cont->get_children ();

View File

@@ -22,6 +22,7 @@
#include <gtkmm.h> #include <gtkmm.h>
#include "../rtengine/rtengine.h" #include "../rtengine/rtengine.h"
Glib::ustring escapeHtmlChars(const Glib::ustring &src);
bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference=true); bool removeIfThere (Gtk::Container* cont, Gtk::Widget* w, bool increference=true);
void thumbInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh); void thumbInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh);
Glib::ustring removeExtension (const Glib::ustring& filename); Glib::ustring removeExtension (const Glib::ustring& filename);