X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fhtml-parse.c;h=4a86627e14a8d7c6968e95a30c595f157476e07b;hp=2a09ff09c0e6cd1c9e8e2cc86867d261e31b16e3;hb=3f84a5e00e255ab46e69d8ff5e565b238fce4126;hpb=1b2dce0493a5695ec1bff8ea9e11a7adc79cff1a diff --git a/src/html-parse.c b/src/html-parse.c index 2a09ff09..4a86627e 100644 --- a/src/html-parse.c +++ b/src/html-parse.c @@ -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, ` '. */ + /* Skip blanks if required. We must do this before entities are + processed, so that blanks can still be inserted as, for instance, + ` '. */ 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.) */