Commit 0c75438
csv: handle empty fields with skipinitialspace
skipinitialspace preprocessed records by trimming both ends of every split
field. Fields containing only spaces could therefore produce an invalid
slice, while trailing spaces were removed even though CPython preserves them.
Trim only field prefixes in the csv-core path and make the remaining
all-space trimming helper return an empty slice safely.
QUOTE_NOTNULL and QUOTE_STRINGS add another distinction: an unquoted empty
field becomes None, but a quoted empty field remains an empty string. Both
forms have identical decoded bytes, so extend the existing QUOTE_NONE custom
reader into one shared path that records whether each field started quoted.
Use that metadata only for the null conversion while retaining QUOTE_NONE
escape behavior.
Unmark Test_Csv.test_read_skipinitialspace now that its standard,
QUOTE_NOTNULL, and QUOTE_STRINGS cases pass.
This keeps the existing one-item reader lifecycle and does not add the larger
strict or multiline parser state machine.
Assisted-by: Codex:gpt-5-sol1 parent 8754004 commit 0c75438
2 files changed
Lines changed: 80 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | | - | |
475 | 474 | | |
476 | 475 | | |
477 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
997 | | - | |
| 997 | + | |
998 | 998 | | |
999 | 999 | | |
1000 | 1000 | | |
1001 | 1001 | | |
1002 | 1002 | | |
1003 | | - | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
1004 | 1008 | | |
1005 | | - | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
1006 | 1013 | | |
1007 | | - | |
1008 | 1014 | | |
1009 | | - | |
| 1015 | + | |
1010 | 1016 | | |
1011 | | - | |
1012 | | - | |
| 1017 | + | |
| 1018 | + | |
1013 | 1019 | | |
1014 | | - | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1015 | 1023 | | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
1016 | 1055 | | |
1017 | | - | |
1018 | | - | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
1019 | 1059 | | |
1020 | 1060 | | |
1021 | 1061 | | |
| |||
1031 | 1071 | | |
1032 | 1072 | | |
1033 | 1073 | | |
1034 | | - | |
1035 | | - | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
1036 | 1077 | | |
1037 | 1078 | | |
1038 | 1079 | | |
1039 | 1080 | | |
1040 | 1081 | | |
1041 | 1082 | | |
1042 | | - | |
| 1083 | + | |
1043 | 1084 | | |
1044 | 1085 | | |
1045 | 1086 | | |
1046 | 1087 | | |
1047 | | - | |
| 1088 | + | |
1048 | 1089 | | |
1049 | 1090 | | |
1050 | 1091 | | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1051 | 1098 | | |
1052 | 1099 | | |
1053 | 1100 | | |
| |||
1086 | 1133 | | |
1087 | 1134 | | |
1088 | 1135 | | |
1089 | | - | |
1090 | | - | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
1091 | 1143 | | |
1092 | 1144 | | |
1093 | 1145 | | |
1094 | 1146 | | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
1095 | 1153 | | |
1096 | 1154 | | |
1097 | 1155 | | |
1098 | 1156 | | |
1099 | | - | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
1100 | 1162 | | |
1101 | 1163 | | |
1102 | 1164 | | |
1103 | 1165 | | |
1104 | 1166 | | |
1105 | | - | |
| 1167 | + | |
1106 | 1168 | | |
1107 | 1169 | | |
1108 | 1170 | | |
| |||
0 commit comments