Skip to content

Commit

Permalink
Fix For Chrome Newline Notation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDavenport committed Nov 22, 2021
1 parent f0f82cc commit 9ba69c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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(_))


Expand Down
6 changes: 6 additions & 0 deletions core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala
Expand Up @@ -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))
}

}

0 comments on commit 9ba69c2

Please sign in to comment.