summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xCHANGELOG.md4
-rw-r--r--influxdb.cabal17
-rw-r--r--src/Database/InfluxDB/Internal/Text.hs5
-rw-r--r--src/Database/InfluxDB/Line.hs2
-rw-r--r--tests/regressions.hs42
5 files changed, 67 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbc0345..5879280 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Revision history for influxdb
+## v1.7.1 - 2019-07-19
+
+* Escape backslashes when encoding `Line`s (#75)
+
## v1.7.0 - 2019-05-03
* Support GHC 8.8.1-alpha1
diff --git a/influxdb.cabal b/influxdb.cabal
index 9662f14..fcbcb27 100644
--- a/influxdb.cabal
+++ b/influxdb.cabal
@@ -1,5 +1,5 @@
name: influxdb
-version: 1.7.0
+version: 1.7.1
synopsis: Haskell client library for InfluxDB
description:
@influxdb@ is a Haskell client library for InfluxDB.
@@ -106,6 +106,21 @@ test-suite doctests
hs-source-dirs: tests
default-language: Haskell2010
+test-suite regressions
+ type: exitcode-stdio-1.0
+ main-is: regressions.hs
+ build-depends:
+ base
+ , containers
+ , influxdb
+ , tasty
+ , tasty-hunit
+ , time
+ , raw-strings-qq >= 1.1 && < 1.2
+ ghc-options: -Wall -threaded
+ hs-source-dirs: tests
+ default-language: Haskell2010
+
executable influx-random-points
if !flag(examples)
buildable: False
diff --git a/src/Database/InfluxDB/Internal/Text.hs b/src/Database/InfluxDB/Internal/Text.hs
index 2b5bcdf..5c11143 100644
--- a/src/Database/InfluxDB/Internal/Text.hs
+++ b/src/Database/InfluxDB/Internal/Text.hs
@@ -5,6 +5,7 @@ module Database.InfluxDB.Internal.Text
, escapeSpaces
, escapeDoubleQuotes
, escapeSingleQuotes
+ , escapeBackslashes
) where
import Data.Text (Text)
import qualified Data.Text as T
@@ -13,9 +14,11 @@ escapeCommas
, escapeEqualSigns
, escapeSpaces
, escapeDoubleQuotes
- , escapeSingleQuotes :: Text -> Text
+ , escapeSingleQuotes
+ , escapeBackslashes :: Text -> Text
escapeCommas = T.replace "," "\\,"
escapeEqualSigns = T.replace "=" "\\="
escapeSpaces = T.replace " " "\\ "
escapeDoubleQuotes = T.replace "\"" "\\\""
escapeSingleQuotes = T.replace "'" "\\'"
+escapeBackslashes = T.replace "\\" "\\\\"
diff --git a/src/Database/InfluxDB/Line.hs b/src/Database/InfluxDB/Line.hs
index af88ec1..3d15e20 100644
--- a/src/Database/InfluxDB/Line.hs
+++ b/src/Database/InfluxDB/Line.hs
@@ -143,7 +143,7 @@ escapeMeasurement :: Measurement -> Text
escapeMeasurement (Measurement text) = escapeCommas $ escapeSpaces text
escapeStringField :: Text -> Text
-escapeStringField = escapeDoubleQuotes
+escapeStringField = escapeDoubleQuotes . escapeBackslashes
buildFieldValue :: LineField -> B.Builder
buildFieldValue = \case
diff --git a/tests/regressions.hs b/tests/regressions.hs
new file mode 100644
index 0000000..d439096
--- /dev/null
+++ b/tests/regressions.hs
@@ -0,0 +1,42 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE QuasiQuotes #-}
+import Data.Time.Clock (UTCTime)
+import Test.Tasty
+import Test.Tasty.HUnit
+import Text.RawString.QQ (r)
+import qualified Data.Map as M
+
+import Database.InfluxDB
+import Database.InfluxDB.Line
+import Database.InfluxDB.Write (writeByteString)
+import qualified Database.InfluxDB.Format as F
+
+main :: IO ()
+main = defaultMain tests
+
+tests :: TestTree
+tests = testGroup "regression tests"
+ [ issue75
+ ]
+
+-- https://github.com/maoe/influxdb-haskell/issues/75
+
+issue75 :: TestTree
+issue75 = testCaseSteps "issue #75" $ \step -> do
+ step "Checking encoded value"
+ let string = [r|bl\"a|]
+ let encoded = encodeLine (scaleTo Nanosecond)
+ $ Line "testing" mempty
+ (M.singleton "test" $ FieldString string)
+ (Nothing :: Maybe UTCTime)
+ encoded @?= [r|testing test="bl\\\"a"|]
+
+ step "Preparing a test database"
+ let db = "issue75"
+ let p = queryParams db
+ manage p $ formatQuery ("DROP DATABASE "%F.database) db
+ manage p $ formatQuery ("CREATE DATABASE "%F.database) db
+
+ step "Checking server response"
+ let wp = writeParams db
+ writeByteString wp encoded