Skip to content

Fragment's stripMargin can change the query #895

Closed
@ValdemarGr

Description

@ValdemarGr

If a query contains whitespace and a margin character (| by default) right behind a codec, the whitespace along with the character will be removed.

We have fixed this locally via:

val hd = fa.parts.headOption
val tl = fa.parts.tail

val hdFmt = hd.map(
  _.bimap(
    _.stripMargin,
    _.map(_.stripMargin)
  )
)

val tlFmt = tl.map(
  _.bimap(
    str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin,
    _.map(str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin)
  )
)
fa.copy(parts = hdFmt.toList ++ tlFmt)

Furthermore, the stripMargin function also removes newlines, which is not the behavior of String's stripMargin.
This causes problems when skunk tries to show where an error occurs when the text is wrapped:
image

The removal of newlines makes big queries particularly difficult to debug.

https://scastie.scala-lang.org/dxh94yyIRBWGfeQNnVGHGg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions