elm-graphql icon indicating copy to clipboard operation
elm-graphql copied to clipboard

betweenQuotes must also encode special characters.

Open ad-si opened this issue 2 years ago • 5 comments

The betweenQuotes function seems to be incorrect as e.g. \n should be encoded as \\n, but all it does is to add the surrounding escape quotes.

Here is a list of all JSON special characters: https://www.tutorialspoint.com/json_simple/json_simple_escape_characters.htm

ad-si avatar Jul 18 '22 15:07 ad-si

Do you know if there's a builtin function, or something to do the escaping directly in Elm?

ghivert avatar Oct 06 '22 08:10 ghivert

Yeah, it's actually just simple JSON encoding the string, so Json.Encode.encode does the job. (https://package.elm-lang.org/packages/elm/json/1.1.3/Json-Encode#encode)

ad-si avatar Oct 06 '22 09:10 ad-si

I guess that means betweenQuotes can simply be replaced with encode 0 😅

ad-si avatar Oct 06 '22 09:10 ad-si

I'll try to ship a new version that WE

ghivert avatar Oct 11 '22 14:10 ghivert

The quick workaround is to replace |> GQL.string with

|> JE.string
|> JE.encode 0
|> GQL.type_

ad-si avatar Nov 10 '22 13:11 ad-si