gtkhtml r9156 - trunk/gtkhtml



Author: tobiasmue
Date: Mon Mar  2 01:39:20 2009
New Revision: 9156
URL: http://svn.gnome.org/viewvc/gtkhtml?rev=9156&view=rev

Log:
2009-03-02  Matt McCutchen  <matt mattmccutchen net>

    Now that gtkhtml's handling of entities in input has been fixed
    comprehensively in bug 552357, revert previous workarounds, as
    follows:

    * gtkhtml/gtkhtml/htmltokenizer.c:
    * gtkhtml/gtkhtml/ChangeLog:
    * gtkhtml/gtkhtml/htmltext.c:
    * gtkhtml/gtkhtml/htmlutils.c:
    * gtkhtml/gtkhtml/htmlutils.h:
    * gtkhtml/gtkhtml/Makefile.am:
    * gtkhtml/gtkhtml/htmlobject.c:
    * gtkhtml/gtkhtml/gtkhtml.c:
    Revert gtkhtml revision 8605 (workaround for bug 485700).

    * gtkhtml/gtkhtml/htmlengine-save.h, gtkhtml/gtkhtml/htmlengine-save.c
    (html_engine_save_delims_and_vals): New function to help output
    properly entity-encoded tags with attributes.

    * gtkhtml/gtkhtml/htmltext.c:
    * gtkhtml/gtkhtml/htmlimage.c:
    * gtkhtml/gtkhtml/htmlobject.c:
    * gtkhtml/gtkhtml/htmliframe.c:
    * gtkhtml/gtkhtml/htmltablecell.c:
    * gtkhtml/gtkhtml/htmltable.c: Entity-encode attributes where
    appropriate.

    ** Part of the fix for bug #549838



Removed:
   trunk/gtkhtml/htmlutils.c
   trunk/gtkhtml/htmlutils.h
Modified:
   trunk/gtkhtml/ChangeLog
   trunk/gtkhtml/Makefile.am
   trunk/gtkhtml/gtkhtml.c
   trunk/gtkhtml/htmlengine-save.c
   trunk/gtkhtml/htmlengine-save.h
   trunk/gtkhtml/htmliframe.c
   trunk/gtkhtml/htmlimage.c
   trunk/gtkhtml/htmlobject.c
   trunk/gtkhtml/htmltable.c
   trunk/gtkhtml/htmltablecell.c
   trunk/gtkhtml/htmltext.c
   trunk/gtkhtml/htmltokenizer.c

Modified: trunk/gtkhtml/Makefile.am
==============================================================================
--- trunk/gtkhtml/Makefile.am	(original)
+++ trunk/gtkhtml/Makefile.am	Mon Mar  2 01:39:20 2009
@@ -128,7 +128,6 @@
 	htmliframe.c				\
 	htmlframe.c				\
 	htmlframeset.c				\
-	htmlutils.c				\
 	gtkhtml-compat.h			\
 	gtkhtml-keybinding.h			\
 	gtkhtml-private.h			\
@@ -203,7 +202,6 @@
 	htmliframe.h				\
 	htmlframe.h				\
 	htmlframeset.h				\
-	htmlutils.h				\
 	$(PLATFORM_DEP_SOURCES)			\
 	$(NULL)
 

Modified: trunk/gtkhtml/gtkhtml.c
==============================================================================
--- trunk/gtkhtml/gtkhtml.c	(original)
+++ trunk/gtkhtml/gtkhtml.c	Mon Mar  2 01:39:20 2009
@@ -59,7 +59,6 @@
 #include "htmltextslave.h"
 #include "htmlselection.h"
 #include "htmlundo.h"
-#include "htmlutils.h"
 
 #include "gtkhtml.h"
 #include "gtkhtml-embedded.h"
@@ -1331,7 +1330,7 @@
 		return;
 
 	g_free (html->pointer_url);
-	html->pointer_url = html_utils_maybe_unescape_amp (url);
+	html->pointer_url = url ? g_strdup (url) : NULL;
 	g_signal_emit (html,  signals[ON_URL], 0, html->pointer_url);
 }
 

Modified: trunk/gtkhtml/htmlengine-save.c
==============================================================================
--- trunk/gtkhtml/htmlengine-save.c	(original)
+++ trunk/gtkhtml/htmlengine-save.c	Mon Mar  2 01:39:20 2009
@@ -202,6 +202,29 @@
 		bytes = strlen (buffer);
 	return state->receiver (state->engine, buffer, bytes, state->user_data);
 }
+
+gboolean
+html_engine_save_delims_and_vals (HTMLEngineSaveState *state,
+				  const gchar *first,
+				  ...)
+{
+  va_list args;
+  gboolean retval;
+  const gchar *value, *after;
+
+  g_return_val_if_fail (state != NULL, FALSE);
+
+  retval = html_engine_save_output_buffer (state, first, -1);
+  va_start (args, first);
+  while (retval && (value = va_arg (args, const gchar *)) != NULL) {
+    after = va_arg (args, const gchar *);
+    retval = html_engine_save_encode_string (state, value)
+	    && html_engine_save_output_buffer (state, after, -1);
+  }
+  va_end (args);
+
+  return retval;
+}
 
 
 static gchar *
@@ -280,9 +303,9 @@
 	if (state->engine->title != NULL
 	    && state->engine->title->str != NULL
 	    && state->engine->title->str[0] != '\0') {
-		if (! html_engine_save_output_string (state, "  <TITLE>")
-		    || ! html_engine_save_encode_string (state, state->engine->title->str)
-		    || ! html_engine_save_output_string (state, "</TITLE>\n"))
+		if (! html_engine_save_delims_and_vals (state,
+				"  <TITLE>", state->engine->title->str,
+				"</TITLE>\n", NULL))
 			return FALSE;
 	}
 

Modified: trunk/gtkhtml/htmlengine-save.h
==============================================================================
--- trunk/gtkhtml/htmlengine-save.h	(original)
+++ trunk/gtkhtml/htmlengine-save.h	Mon Mar  2 01:39:20 2009
@@ -64,6 +64,16 @@
 								 const gchar               *buffer,
 								 int                        len);
 
+/* Takes a string sequence of the form (delim, (val, delim)*, NULL)
+   and outputs the delimiters verbatim and the values entity-encoded.
+   Useful for writing properly-encoded tags with attributes.
+
+   Example: html_engine_save_delims_and_vals (state, "<TAG ATTR1=\"", attr1, "\" ATTR2=\"", attr2, "\">", NULL);
+   */
+gboolean             html_engine_save_delims_and_vals           (HTMLEngineSaveState *state,
+								 const gchar *first,
+								 ...);
+
 /* Saving a whole tree.  */
 gboolean             html_engine_save                           (HTMLEngine                *engine,
 								 HTMLEngineSaveReceiverFn   receiver,

Modified: trunk/gtkhtml/htmliframe.c
==============================================================================
--- trunk/gtkhtml/htmliframe.c	(original)
+++ trunk/gtkhtml/htmliframe.c	Mon Mar  2 01:39:20 2009
@@ -493,7 +493,7 @@
 		}
 		html_engine_save_buffer_free (buffer, TRUE);
 	} else {
-		if (!html_engine_save_output_string (state, "<IFRAME SRC=\"%s\"", iframe->url))
+		if (!html_engine_save_delims_and_vals (state, "<IFRAME SRC=\"", iframe->url, "\"", NULL))
 			 return FALSE;
 
 		 if (iframe->width >= 0)

Modified: trunk/gtkhtml/htmlimage.c
==============================================================================
--- trunk/gtkhtml/htmlimage.c	(original)
+++ trunk/gtkhtml/htmlimage.c	Mon Mar  2 01:39:20 2009
@@ -599,14 +599,14 @@
 	if (image->url && *image->url) {
 		url  = g_strconcat (image->url, image->target ? "#" : "", image->target, NULL);
 		link = TRUE;
-		result = html_engine_save_output_string (state, "<A HREF=\"%s\">", url);
+		result = html_engine_save_delims_and_vals (state, "<A HREF=\"", url, "\">", NULL);
 		g_free (url);
 		if (!result)
 			return FALSE;
 	}
 
 	url    = html_image_resolve_image_url (state->engine->widget, image->image_ptr->url);
-	result = html_engine_save_output_string (state, "<IMG SRC=\"%s\"", url);
+	result = html_engine_save_delims_and_vals (state, "<IMG SRC=\"", url, "\"", NULL);
 	g_free (url);
 	if (!result)
 		return FALSE;
@@ -648,7 +648,7 @@
 	}
 
 	if (image->alt) {
-		if (!html_engine_save_output_string (state, " ALT=\"%s\"", image->alt))
+		if (!html_engine_save_delims_and_vals (state, " ALT=\"", image->alt, "\"", NULL))
 			return FALSE;
 	}
 

Modified: trunk/gtkhtml/htmlobject.c
==============================================================================
--- trunk/gtkhtml/htmlobject.c	(original)
+++ trunk/gtkhtml/htmlobject.c	Mon Mar  2 01:39:20 2009
@@ -45,7 +45,6 @@
 #include "htmlrule.h"
 #include "htmltype.h"
 #include "htmlsettings.h"
-#include "htmlutils.h"
 
 #include "gtkhtmldebug.h"
 
@@ -1172,16 +1171,11 @@
 html_object_get_complete_url (HTMLObject *o, gint offset)
 {
 	const gchar *url, *target;
-	gchar *url2, *url3;
 
 	url = html_object_get_url (o, offset);
 	target = html_object_get_target (o, offset);
-	url2 = url || target ? g_strconcat (url ? url : "#", url ? (target && *target ? "#" : NULL) : target,
-					    url ? target : NULL, NULL) : NULL;
-	url3 = html_utils_maybe_unescape_amp (url2);
-	g_free (url2);
-
-	return url3;
+	return url || target ? g_strconcat (url ? url : "#", url ? (target && *target ? "#" : NULL) : target,
+					      url ? target : NULL, NULL) : NULL;
 }
 
 const gchar *
@@ -1857,8 +1851,11 @@
 	/* printf ("object %s %s\n", g_quark_to_string (key_id), str); */
 	if (!str) {
 		/* printf ("save %s %s -> %s\n", state->save_data_class_name, g_quark_to_string (key_id), (gchar *) data); */
-		html_engine_save_output_string (state, "<!--+GtkHTML:<DATA class=\"%s\" key=\"%s\" value=\"%s\">-->",
-						state->save_data_class_name, g_quark_to_string (key_id), (char *) data);
+		html_engine_save_delims_and_vals (state,
+				"<!--+GtkHTML:<DATA class=\"", state->save_data_class_name,
+				"\" key=\"", g_quark_to_string (key_id),
+				"\" value=\"", (char *) data,
+				"\">-->", NULL);
 		html_engine_set_class_data (state->engine, state->save_data_class_name, g_quark_to_string (key_id), data);
 	}
 }
@@ -1873,13 +1870,18 @@
 	/* printf ("handle: %s %s %s %s\n", state->save_data_class_name, key, value, str); */
 	if (!str) {
 		/* printf ("clear\n"); */
-		html_engine_save_output_string (state, "<!--+GtkHTML:<DATA class=\"%s\" clear=\"%s\">-->",
-						state->save_data_class_name, (char *) key);
+		html_engine_save_delims_and_vals (state,
+				"<!--+GtkHTML:<DATA class=\"", state->save_data_class_name,
+				"\" clear=\"", (char *) key,
+				"\">-->", NULL);
 		state->data_to_remove = g_slist_prepend (state->data_to_remove, key);
 	} else if (strcmp (value, str)) {
 		/* printf ("change\n"); */
-		html_engine_save_output_string (state, "<!--+GtkHTML:<DATA class=\"%s\" key=\"%s\" value=\"%s\">-->",
-						state->save_data_class_name, (char *) key, str);
+		html_engine_save_delims_and_vals (state,
+				"<!--+GtkHTML:<DATA class=\"", state->save_data_class_name,
+				"\" key=\"", (char *) key,
+				"\" value=\"", str,
+				"\">-->", NULL);
 		html_engine_set_class_data (state->engine, state->save_data_class_name, key, value);
 	}
 }

Modified: trunk/gtkhtml/htmltable.c
==============================================================================
--- trunk/gtkhtml/htmltable.c	(original)
+++ trunk/gtkhtml/htmltable.c	Mon Mar  2 01:39:20 2009
@@ -2129,7 +2129,11 @@
 			table->bgColor->blue >> 8 SE;
 	if (table->bgPixmap) {
 		gchar * url = html_image_resolve_image_url (state->engine->widget, table->bgPixmap->url);
-		SB " BACKGROUND=\"%s\"", url SE;
+		if (!html_engine_save_delims_and_vals (state, " BACKGROUND=\"", url, "\"", NULL))
+		{
+			g_free (url);
+			return FALSE;
+		}
 		g_free (url);
 	}
 	if (table->spacing != 2)

Modified: trunk/gtkhtml/htmltablecell.c
==============================================================================
--- trunk/gtkhtml/htmltablecell.c	(original)
+++ trunk/gtkhtml/htmltablecell.c	Mon Mar  2 01:39:20 2009
@@ -288,7 +288,11 @@
 
 	if (cell->have_bgPixmap) {
 		gchar * url = html_image_resolve_image_url (state->engine->widget, cell->bgPixmap->url);
-		SB " BACKGROUND=\"%s\"", url SE;
+		if (!html_engine_save_delims_and_vals (state, " BACKGROUND=\"", url, "\"", NULL))
+		{
+			g_free (url);
+			return FALSE;
+		}
 		g_free (url);
 	}
 	if (cell->cspan != 1)

Modified: trunk/gtkhtml/htmltext.c
==============================================================================
--- trunk/gtkhtml/htmltext.c	(original)
+++ trunk/gtkhtml/htmltext.c	Mon Mar  2 01:39:20 2009
@@ -49,7 +49,6 @@
 #include "htmlsettings.h"
 #include "htmltextslave.h"
 #include "htmlundo.h"
-#include "htmlutils.h"
 
 HTMLTextClass html_text_class;
 static HTMLObjectClass *parent_class = NULL;
@@ -1749,7 +1748,9 @@
 static gboolean
 save_link_open (Link *link, HTMLEngineSaveState *state)
 {
-	return html_engine_save_output_string (state, "<A HREF=\"%s\">", link->url);
+	return html_engine_save_delims_and_vals (state,
+			"<A HREF=\"", link->url,
+			"\">", NULL);
 }
 
 static gboolean
@@ -3525,8 +3526,8 @@
 	g_free (link->url);
 	g_free (link->target);
 
-	link->url = html_utils_maybe_escape_amp (url);
-	link->target = html_utils_maybe_escape_amp (target);
+	link->url = g_strdup (url);
+	link->target = g_strdup (target);
 }
 
 Link *
@@ -3567,8 +3568,8 @@
 {
 	Link *link = g_new0 (Link, 1);
 
-	link->url = html_utils_maybe_escape_amp (url);
-	link->target = html_utils_maybe_escape_amp (target);
+	link->url = g_strdup (url);
+	link->target = g_strdup (target);
 	link->start_offset = start_offset;
 	link->end_offset = end_offset;
 	link->start_index = start_index;

Modified: trunk/gtkhtml/htmltokenizer.c
==============================================================================
--- trunk/gtkhtml/htmltokenizer.c	(original)
+++ trunk/gtkhtml/htmltokenizer.c	Mon Mar  2 01:39:20 2009
@@ -90,7 +90,6 @@
 	gint     pre; /* Are we in a <pre> block? */
 	gboolean select; /* Are we in a <select> block? */
 	gboolean extension; /* Are we in an <!-- +GtkHTML: sequence? */
-	gboolean aTag; /* Are we in a <a/> tag*/
 
 	enum {
 		NoneDiscard = 0,
@@ -275,7 +274,6 @@
 	p->pre = 0;
 	p->select = FALSE;
 	p->extension = FALSE;
-	p->aTag = FALSE;
 
 	p->discard = NoneDiscard;
 	p->pending = NonePending;
@@ -1166,7 +1164,6 @@
 	p->dest = p->buffer;
 
 	p->tag = FALSE;
-	p->aTag = FALSE;
 	p->pending = NonePending;
 	(*src)++;
 
@@ -1280,8 +1277,6 @@
 		if (t->priv->discard == NoneDiscard)
 			t->priv->pending = SpacePending;
 		ptr = t->priv->buffer;
-		if (strlen (ptr) == 3 && ptr[1] == '<' && ptr[2] == 'a')
-			t->priv->aTag = TRUE;
 	}
 	else if (t->priv->pre || t->priv->textarea) {
 		if (t->priv->pending)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]