Unescape HTML entities when importing bookmarks from Netscape HTML.

This commit is contained in:
Paweł Forysiuk 2011-02-16 16:47:09 +01:00 committed by Christian Dywan
parent e272fc04f2
commit 2c4015ab94

View file

@ -293,6 +293,45 @@ katze_array_from_xmlDocPtr (KatzeArray* array,
return TRUE; return TRUE;
} }
static gchar*
katze_unescape_html (const gchar* text)
{
gchar* amp = g_strstr_len (text, -1, "&");
if (amp && *amp)
{
if (!strncmp (amp, """, 6) || !strncmp (amp, "&", 5)
|| !strncmp (amp, "<", 4) || !strncmp (amp, ">", 4)
|| !strncmp (amp, "'", 6))
{
guint i = 0;
gchar** parts = g_strsplit_set (text, "&;", -1);
GString *unescaped = g_string_new (NULL);
while (parts[i])
{
if (katze_str_equal ("quot", parts[i]))
g_string_append (unescaped, "\"");
else if (katze_str_equal ("amp", parts[i]))
g_string_append (unescaped, "&");
else if (katze_str_equal ("lt", parts[i]))
g_string_append (unescaped, "<");
else if (katze_str_equal ("gt", parts[i]))
g_string_append (unescaped, ">");
else if (katze_str_equal ("apos", parts[i]))
g_string_append (unescaped, "'");
else
g_string_append (unescaped, parts[i]);
i++;
}
g_strfreev (parts);
return g_string_free (unescaped, FALSE);
}
}
return g_strdup (text);
}
static gboolean static gboolean
katze_array_from_netscape_file (KatzeArray* array, katze_array_from_netscape_file (KatzeArray* array,
const gchar* filename) const gchar* filename)
@ -322,8 +361,8 @@ katze_array_from_netscape_file (KatzeArray* array,
gchar** parts = g_strsplit (line, "\"", -1); gchar** parts = g_strsplit (line, "\"", -1);
item = katze_item_new (); item = katze_item_new ();
katze_array_add_item (folder, item); katze_array_add_item (folder, item);
item->name = g_strdup (element[4]); item->name = katze_unescape_html (element[4]);
item->uri = g_strdup (parts[1]); item->uri = katze_unescape_html (parts[1]);
g_strfreev (parts); g_strfreev (parts);
} }
/* item is folder */ /* item is folder */
@ -332,14 +371,14 @@ katze_array_from_netscape_file (KatzeArray* array,
item = (KatzeItem*)katze_array_new (KATZE_TYPE_ARRAY); item = (KatzeItem*)katze_array_new (KATZE_TYPE_ARRAY);
katze_array_add_item (folder, item); katze_array_add_item (folder, item);
folder = (KatzeArray*)item; folder = (KatzeArray*)item;
item->name = g_strdup (element[4]); item->name = katze_unescape_html (element[4]);
} }
} }
/* item description */ /* item description */
if (item && katze_str_equal (element[1], "DD")) if (item && katze_str_equal (element[1], "DD"))
{ {
if (element[2]) if (element[2])
item->text = g_strdup (element[2]); item->text = katze_unescape_html (element[2]);
item = NULL; item = NULL;
} }
/* end of current folder, level-up */ /* end of current folder, level-up */