]> granicus.if.org Git - php/commitdiff
Fix 'soft line break' handling in convert.quoted-printable-decode
authorSara Golemon <pollita@php.net>
Mon, 17 Apr 2006 19:25:48 +0000 (19:25 +0000)
committerSara Golemon <pollita@php.net>
Mon, 17 Apr 2006 19:25:48 +0000 (19:25 +0000)
ext/standard/filters.c

index 7b07514fc884cd0a60b3e6b1fbd6c734f0e5752c..f16a2ec9f8dff33e4ce559992b1b39e1827cfcd4 100644 (file)
@@ -1108,6 +1108,18 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
                                        scan_stat = 4;
                                        ps++, icnt--;
                                        break;
+                               } else if (!inst->lbchars && lb_cnt == 0 && *ps == '\r') {
+                                       /* auto-detect line endings, looks like network line ending \r\n (could be mac \r) */
+                                       lb_cnt++;
+                                       scan_stat = 5;
+                                       ps++, icnt--;
+                                       break;
+                               } else if (!inst->lbchars && lb_cnt == 0 && *ps == '\n') {
+                                       /* auto-detect line endings, looks like unix-lineendings, not to spec, but it is seem in the wild, a lot */
+                                       lb_cnt = lb_ptr = 0;
+                                       scan_stat = 0;
+                                       ps++, icnt--;
+                                       break;
                                } else if (lb_cnt < inst->lbchars_len &&
                                                        *ps == (unsigned char)inst->lbchars[lb_cnt]) {
                                        lb_cnt++;
@@ -1165,7 +1177,16 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
                        } break;
 
                        case 5: {
-                               if (lb_cnt >= inst->lbchars_len) {
+                               if (!inst->lbchars && lb_cnt == 1 && *ps == '\n') {
+                                       /* auto-detect soft line breaks, found network line break */
+                                       lb_cnt = lb_ptr = 0;
+                                       scan_stat = 0;
+                                       ps++, icnt--; /* consume \n */
+                               } else if (!inst->lbchars && lb_cnt > 0) {
+                                       /* auto-detect soft line breaks, found mac line break */
+                                       lb_cnt = lb_ptr = 0;
+                                       scan_stat = 0;
+                               } else if (lb_cnt >= inst->lbchars_len) {
                                        /* soft line break */
                                        lb_cnt = lb_ptr = 0;
                                        scan_stat = 0;
@@ -1486,10 +1507,6 @@ static php_conv *php_conv_open(int conv_mode, const HashTable *options, int pers
 
                        if (options != NULL) {
                                GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0);
-                               if (lbchars == NULL) {
-                                       lbchars = pestrdup("\r\n", 0);
-                                       lbchars_len = 2;
-                               }
                        }
                        retval = pemalloc(sizeof(php_conv_qprint_decode), persistent);
                        if (lbchars != NULL) {