]> sjero.net Git - wget/commitdiff
[svn] Squash embedded newlines in links.
authorhniksic <devnull@localhost>
Wed, 26 Nov 2003 16:37:04 +0000 (08:37 -0800)
committerhniksic <devnull@localhost>
Wed, 26 Nov 2003 16:37:04 +0000 (08:37 -0800)
src/ChangeLog
src/html-parse.c
src/html-url.c

index 24ae86fa78d520f7a4e58aeb8e4a42673b3e38db..c6a4f660f14b12e131483f8b4872ce6bff9da41f 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-26  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * html-parse.c (convert_and_copy): Remove embedded newlines when
+       AP_TRIM_BLANKS is specified.
+
 2003-11-26  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * ftp.c: Set con->csock to -1 where rbuf_uninitialize was
index 2a09ff09c0e6cd1c9e8e2cc86867d261e31b16e3..4a86627e14a8d7c6968e95a30c595f157476e07b 100644 (file)
@@ -360,17 +360,16 @@ enum {
      the ASCII range when copying the string.
 
    * AP_TRIM_BLANKS -- ignore blanks at the beginning and at the end
-     of text.  */
+     of text, as well as embedded newlines.  */
 
 static void
 convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags)
 {
   int old_tail = pool->tail;
-  int size;
 
-  /* First, skip blanks if required.  We must do this before entities
-     are processed, so that blanks can still be inserted as, for
-     instance, `&#32;'.  */
+  /* Skip blanks if required.  We must do this before entities are
+     processed, so that blanks can still be inserted as, for instance,
+     `&#32;'.  */
   if (flags & AP_TRIM_BLANKS)
     {
       while (beg < end && ISSPACE (*beg))
@@ -378,7 +377,6 @@ convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags
       while (end > beg && ISSPACE (end[-1]))
        --end;
     }
-  size = end - beg;
 
   if (flags & AP_DECODE_ENTITIES)
     {
@@ -391,15 +389,14 @@ convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags
         never lengthen it.  */
       const char *from = beg;
       char *to;
+      int squash_newlines = flags & AP_TRIM_BLANKS;
 
       POOL_GROW (pool, end - beg);
       to = pool->contents + pool->tail;
 
       while (from < end)
        {
-         if (*from != '&')
-           *to++ = *from++;
-         else
+         if (*from == '&')
            {
              int entity = decode_entity (&from, end);
              if (entity != -1)
@@ -407,6 +404,10 @@ convert_and_copy (struct pool *pool, const char *beg, const char *end, int flags
              else
                *to++ = *from++;
            }
+         else if ((*from == '\n' || *from == '\r') && squash_newlines)
+           ++from;
+         else
+           *to++ = *from++;
        }
       /* Verify that we haven't exceeded the original size.  (It
         shouldn't happen, hence the assert.)  */
index 89b93539d65f926c26997b76bec953fb26faecce..59d873b394e6443cbaacad970399fbf6b67596f3 100644 (file)
@@ -612,9 +612,12 @@ get_urls_html (const char *file, const char *url, int *meta_disallow_follow)
     init_interesting ();
 
   /* Specify MHT_TRIM_VALUES because of buggy HTML generators that
-     generate <a href=" foo"> instead of <a href="foo"> (Netscape
-     ignores spaces as well.)  If you really mean space, use &32; or
-     %20.  */
+     generate <a href=" foo"> instead of <a href="foo"> (browsers
+     ignore spaces as well.)  If you really mean space, use &32; or
+     %20.  MHT_TRIM_VALUES also causes squashing of embedded newlines,
+     e.g. in <img src="foo.[newline]html">.  Such newlines are also
+     ignored by IE and Mozilla and are presumably introduced by
+     writing HTML with editors that force word wrap.  */
   flags = MHT_TRIM_VALUES;
   if (opt.strict_comments)
     flags |= MHT_STRICT_COMMENTS;