@@ -113,6 +113,9 @@ cdef inline void extract_all_values(
113113 cdef int quote_offset
114114 cdef int i
115115 cdef int found_count = 0
116+ cdef int key_matched = 0
117+ cdef const char * dummy_ptr
118+ cdef Py_ssize_t dummy_len
116119
117120 while pos < end and found_count < num_cols:
118121 # Find opening quote for key
@@ -137,6 +140,7 @@ cdef inline void extract_all_values(
137140
138141 # Check if this key matches any of our columns
139142 key_len = quote_offset
143+ key_matched = 0
140144 for i in range (num_cols):
141145 if not found_flags[i] and key_lengths[i] == key_len:
142146 if memcmp(key_start, key_ptrs[i], < size_t> key_len) == 0 :
@@ -156,9 +160,27 @@ cdef inline void extract_all_values(
156160 if extract_value(value_start, end - value_start, & value_ptrs[i], & value_lens[i]):
157161 found_flags[i] = 1
158162 found_count += 1
163+ # Advance position past the extracted value
164+ pos = value_start + value_lens[i]
165+ key_matched = 1
159166 break
160167
161- pos = key_start + key_len + 1
168+ # If key didn't match any requested columns, skip over its value
169+ if not key_matched:
170+ value_start = key_start + key_len + 1 # Skip closing quote of key
171+
172+ # Skip whitespace and colon
173+ while value_start < end and (value_start[0 ] in (32 , 9 , 13 , 58 )):
174+ value_start += 1
175+
176+ if value_start < end:
177+ # Extract (and discard) the value to advance position correctly
178+ if extract_value(value_start, end - value_start, & dummy_ptr, & dummy_len):
179+ pos = value_start + dummy_len
180+ else :
181+ pos = key_start + key_len + 1
182+ else :
183+ pos = key_start + key_len + 1
162184
163185cdef inline int extract_value(
164186 const char * value_start, Py_ssize_t remaining,
0 commit comments