]> sjero.net Git - wget/commitdiff
[svn] Process attributes in order in which they appear in the tag.
authorhniksic <devnull@localhost>
Fri, 16 Nov 2001 19:44:42 +0000 (11:44 -0800)
committerhniksic <devnull@localhost>
Fri, 16 Nov 2001 19:44:42 +0000 (11:44 -0800)
Submitted by Ian Abbott in <3B868388.6538.14A7848@localhost>
based on analysis by Edward Sabol.

src/ChangeLog
src/html-url.c

index 07dc71412d63ca4eaf70053af3d1e29eec8a18c3..ec409e108eae29ff0bc26b6caea546208dcd22c7 100644 (file)
@@ -1,3 +1,9 @@
+2001-08-24  Ian Abbott  <abbotti@mev.co.uk>
+
+       * html-url.c (collect_tags_mapper): Fix bug converting links
+       with -k option for tags with multiple link attributes by
+       handling links in the order they appear.
+
 2001-08-15  Ian Abbott  <abbotti@mev.co.uk>
 
        * ftp.c (ftp_loop_internal): Avoid a potential buffer overflow in
index 0659edd51c4427e129d57006cdc5f83f27a20433..03290853a1762c7ab7d70056d48eac43a589dd4d 100644 (file)
@@ -383,7 +383,7 @@ collect_tags_mapper (struct taginfo *tag, void *arg)
     {
     case TC_LINK:
       {
-       int i;
+       int i, id, first;
        int size = ARRAY_SIZE (url_tag_attr_map);
        for (i = 0; i < size; i++)
          if (url_tag_attr_map[i].tagid == tagid)
@@ -391,25 +391,34 @@ collect_tags_mapper (struct taginfo *tag, void *arg)
        /* We've found the index of url_tag_attr_map where the
            attributes of our tags begin.  Now, look for every one of
            them, and handle it.  */
-       for (; (i < size && url_tag_attr_map[i].tagid == tagid); i++)
+       /* Need to process the attributes in the order they appear in
+          the tag, as this is required if we convert links.  */
+       first = i;
+       for (id = 0; id < tag->nattrs; id++)
          {
-           char *attr_value;
-           int id;
-           if (closure->dash_p_leaf_HTML
-               && (url_tag_attr_map[i].flags & AF_EXTERNAL))
-             /* If we're at a -p leaf node, we don't want to retrieve
-                 links to references we know are external to this document,
-                such as <a href=...>.  */
-             continue;
-
-           /* This find_attr() buried in a loop may seem inefficient
-               (O(n^2)), but it's not, since the number of attributes
-               (n) we loop over is extremely small.  In the worst case
-               of IMG with all its possible attributes, n^2 will be
-               only 9.  */
-           attr_value = find_attr (tag, url_tag_attr_map[i].attr_name, &id);
-           if (attr_value)
-             handle_link (closure, attr_value, tag, id);
+           /* This nested loop may seem inefficient (O(n^2)), but it's
+              not, since the number of attributes (n) we loop over is
+              extremely small.  In the worst case of IMG with all its
+              possible attributes, n^2 will be only 9.  */
+           for (i = first; (i < size && url_tag_attr_map[i].tagid == tagid);
+                i++)
+             {
+               char *attr_value;
+               if (closure->dash_p_leaf_HTML
+                   && (url_tag_attr_map[i].flags & AF_EXTERNAL))
+                 /* If we're at a -p leaf node, we don't want to retrieve
+                    links to references we know are external to this document,
+                    such as <a href=...>.  */
+                 continue;
+
+               if (!strcasecmp (tag->attrs[id].name,
+                                url_tag_attr_map[i].attr_name))
+                 {
+                   attr_value = tag->attrs[id].value;
+                   if (attr_value)
+                     handle_link (closure, attr_value, tag, id);
+                 }
+             }
          }
       }
       break;