@@ -1031,6 +1031,18 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
1031
1031
scan_stat = 4 ;
1032
1032
ps ++ , icnt -- ;
1033
1033
break ;
1034
+ } else if (!inst -> lbchars && lb_cnt == 0 && * ps == '\r' ) {
1035
+ /* auto-detect line endings, looks like network line ending \r\n (could be mac \r) */
1036
+ lb_cnt ++ ;
1037
+ scan_stat = 5 ;
1038
+ ps ++ , icnt -- ;
1039
+ break ;
1040
+ } else if (!inst -> lbchars && lb_cnt == 0 && * ps == '\n' ) {
1041
+ /* auto-detect line endings, looks like unix-lineendings, not to spec, but it is seem in the wild, a lot */
1042
+ lb_cnt = lb_ptr = 0 ;
1043
+ scan_stat = 0 ;
1044
+ ps ++ , icnt -- ;
1045
+ break ;
1034
1046
} else if (lb_cnt < inst -> lbchars_len &&
1035
1047
* ps == (unsigned char )inst -> lbchars [lb_cnt ]) {
1036
1048
lb_cnt ++ ;
@@ -1088,7 +1100,16 @@ static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *ins
1088
1100
} break ;
1089
1101
1090
1102
case 5 : {
1091
- if (lb_cnt >= inst -> lbchars_len ) {
1103
+ if (!inst -> lbchars && lb_cnt == 1 && * ps == '\n' ) {
1104
+ /* auto-detect soft line breaks, found network line break */
1105
+ lb_cnt = lb_ptr = 0 ;
1106
+ scan_stat = 0 ;
1107
+ ps ++ , icnt -- ; /* consume \n */
1108
+ } else if (!inst -> lbchars && lb_cnt > 0 ) {
1109
+ /* auto-detect soft line breaks, found mac line break */
1110
+ lb_cnt = lb_ptr = 0 ;
1111
+ scan_stat = 0 ;
1112
+ } else if (lb_cnt >= inst -> lbchars_len ) {
1092
1113
/* soft line break */
1093
1114
lb_cnt = lb_ptr = 0 ;
1094
1115
scan_stat = 0 ;
@@ -1408,12 +1429,10 @@ static php_conv *php_conv_open(int conv_mode, const HashTable *options, int pers
1408
1429
size_t lbchars_len ;
1409
1430
1410
1431
if (options != NULL ) {
1432
+ /* If line-break-chars are not specified, filter will attempt to detect line endings (\r, \n, or \r\n) */
1411
1433
GET_STR_PROP (options , lbchars , lbchars_len , "line-break-chars" , 0 );
1412
- if (lbchars == NULL ) {
1413
- lbchars = pestrdup ("\r\n" , 0 );
1414
- lbchars_len = 2 ;
1415
- }
1416
1434
}
1435
+
1417
1436
retval = pemalloc (sizeof (php_conv_qprint_decode ), persistent );
1418
1437
if (lbchars != NULL ) {
1419
1438
if (php_conv_qprint_decode_ctor ((php_conv_qprint_decode * )retval , lbchars , lbchars_len , 1 , persistent )) {
0 commit comments