haskell-hvr / cassava

A CSV parsing and encoding library optimized for ease of use and high performance
http://hackage.haskell.org/package/cassava
BSD 3-Clause "New" or "Revised" License
222 stars 105 forks source link

Fix for exception on hanging doublequote #222

Closed gzh closed 1 month ago

gzh commented 1 year ago

Hi,

There's a problem with escaped fields parser, -- it is partial on opening double quote. Means, it throws Haskell error instead of properly failing. The problem is because of ByteString.init being called on possibly empty bytestring (w/o checking). This small PR suggest a fix for this, plus adds some tests for decoding of escaped input.

yitz-zoomin commented 8 months ago

@andreasabel @phadej Any updates on this simple fix for a nasty bug (caused by use of partial function init)?

andreasabel commented 8 months ago

Tests are failing, e.g. https://github.com/haskell-hvr/cassava/actions/runs/7400077740/job/20151432820?pr=222#step:20:84

escapedMalformed1: [Failed]

Building the tests also fails, e.g. https://github.com/haskell-hvr/cassava/actions/runs/7400077740/job/20151434424?pr=222#step:19:34

tests/UnitTests.hs:64:52: error: • Variable not in scope: (<>) :: IO a0 -> String -> Assertion

andreasabel commented 1 month ago

Fixup of this PR in