SWI-Prolog / packages-http

The SWI-Prolog HTTP server and client libraries
24 stars 23 forks source link

FIXED: Also escape line terminators when writing graphql strings #154

Closed eshelyaron closed 2 years ago

eshelyaron commented 2 years ago

I stumbled upon this issue while porting my sourcehut.pl package to use the new library(http/graphql):

As per https://spec.graphql.org/draft/#StringCharacter, GraphQL does not allow for line terminators (\r and/or \n) to occur in regular string literals (they are allowed in block strings, which use """ instead of " as delimiters). This is in contrast to Prolog strings, which do not impose this limitation. Hence, line terminators that occur in Prolog strings must be escaped This mismatch gave rise to an issue when they are incorporated in GraphQL, e.g. via quasi-quotation.

This PR adds escaping for line terminators in strings written as part of graphql_document_to_{codes,string}/3, and adds a relevant test case.