From 9ba69c2d85231b1138738e7640ad4ed88ba1d75c Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Mon, 22 Nov 2021 09:21:40 -0800 Subject: [PATCH] Fix For Chrome Newline Notation --- .../io/chrisdavenport/curly/CurlyParser.scala | 14 +++++++------- .../scala/io/chrisdavenport/curly/MainSpec.scala | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala b/core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala index 63075d3..e5cf5e0 100644 --- a/core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala +++ b/core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala @@ -42,7 +42,7 @@ object CurlyParser { val curl = sp.? *> P.ignoreCase("curl") *> sp - val uri = P.char('\'') *> P.until(P.char('\'')) <* P.char('\'') <* sp.? + val dropUntilNext = P.until(P.not(sp | P.char('\\'))).void case class OptC(short: Option[Char], long: String, hasValue: Boolean) @@ -191,14 +191,14 @@ object CurlyParser { def parseOptC(optC: OptC): P[Opts] = { val short = optC.short match{ - case Some(c) => P.string("-") *> P.char(c) <* sp.?.void + case Some(c) => P.string("-") *> P.char(c) <* dropUntilNext.?.void case None => P.fail } - val long = P.string("--") *> P.string(optC.long) <* sp.?.void + val long = P.string("--") *> P.string(optC.long) <* dropUntilNext.?.void val code = short | long val body = if (optC.hasValue) { - P.char('$').? *> P.char('\'') *> P.until(P.char('\'')).map(_.some) <* P.char('\'') <* sp.? | - P.until(sp).map(_.some) <* sp.? + P.char('$').? *> P.char('\'') *> P.until(P.char('\'')).map(_.some) <* P.char('\'') <* dropUntilNext.? | + P.until(sp).map(_.some) <* dropUntilNext.? } else P.unit.as(None) (code *> body).map{ case Some(value) => Opts.Opt(optC.long, value) @@ -207,8 +207,8 @@ object CurlyParser { } val unhandled: P[Opts.Unhandled] = ( - P.char('$').?.with1 *> P.char('\'') *> P.until(P.char('\'')) <* P.char('\'') <* sp.? | - P.until(sp) <* sp.? + P.char('$').?.with1 *> P.char('\'') *> P.until(P.char('\'')) <* P.char('\'') <* dropUntilNext.? | + P.until(sp) <* dropUntilNext.? ).map(Opts.Unhandled(_)) diff --git a/core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala b/core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala index 288303a..104a7f0 100644 --- a/core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala +++ b/core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala @@ -42,4 +42,10 @@ class MainSpec extends munit.FunSuite { assertEquals(actual.map(_.length), Right(4)) } + test("with slash new line notation") { + val cmd = """curl 'https://typelevel.org/' \ -H 'User-Agent: Mozilla/5.0' \ --compress \ -H 'Connection: keep-alive'""" + val actual = CurlyParser.all.parseAll(cmd) + assertEquals(actual.map(_.length), Right(4)) + } + }