From 3d9dda6485f8f2afeba68c6514d45b9521938fa3 Mon Sep 17 00:00:00 2001 From: hniksic Date: Fri, 16 Nov 2001 11:44:42 -0800 Subject: [PATCH] [svn] Process attributes in order in which they appear in the tag. Submitted by Ian Abbott in <3B868388.6538.14A7848@localhost> based on analysis by Edward Sabol. --- src/ChangeLog | 6 ++++++ src/html-url.c | 47 ++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 07dc7141..ec409e10 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2001-08-24 Ian Abbott + + * 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 * ftp.c (ftp_loop_internal): Avoid a potential buffer overflow in diff --git a/src/html-url.c b/src/html-url.c index 0659edd5..03290853 100644 --- a/src/html-url.c +++ b/src/html-url.c @@ -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 . */ - 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 . */ + 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; -- 2.39.2