howiezhao opened a new pull request, #4780:
URL: https://github.com/apache/cassandra/pull/4780

   ## Issue
   
   `COPY TO` followed by `COPY FROM` corrupts string values containing 
backslashes on Python 3.10+: the backslash count doubles on every round-trip. 
For example, `https:\/\/google.com` becomes `https:\\/\\/google.com` after one 
cycle.
   
   ## RC
   
   There are two independent backslash-escaping layers in the COPY pipeline:
   
   1. **`format_value_text`** (pre-doubling, always present): doubles every `\` 
→ `\\` before passing to `csv.writer`
   2. **`csv.writer` escapechar handling** (Python-version-dependent): Python 
3.10 fixed [bpo-12178](https://bugs.python.org/issue12178), making `csv.writer` 
properly escape `\` → `\\` in all fields
   
   Before Python 3.10, `csv.writer` did **not** escape bare backslashes in 
unquoted fields, so the pre-doubling from `format_value_text` was exactly 
cancelled by `csv.reader` on import. After Python 3.10, both layers apply, but 
`csv.reader` only removes one — leaving the value with doubled backslashes.
   
   ## Fix
   
   In `ExportProcess.format_value`, undo `format_value_text`'s pre-doubling on 
Python 3.10+ before handing the value to `csv.writer`, making `csv.writer` the 
sole escaping layer:
   
   ```python
   if sys.version_info >= (3, 10):
       formatted = formatted.replace('\\\\', '\\')
   ```
   
   No change for Python < 3.10.
   
   <img width="883" height="725" alt="Screenshot 2026-04-30 at 17 46 36" 
src="https://github.com/user-attachments/assets/7160d7d0-a8a5-4862-aa78-60a160be4f8e";
 />


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to