Browse Source

Fix 'soft line break' handling in convert.quoted-printable-decode

migration/RELEASE_1_0_0
Sara Golemon 21 years ago
parent
commit
04ecb8b1fd
  1. 27
      ext/standard/filters.c

27
ext/standard/filters.c

@ -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) {

Loading…
Cancel
Save