Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix For Chrome Newline Notation #16

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions core/src/main/scala/io/chrisdavenport/curly/CurlyParser.scala
Original file line number Diff line number Diff line change
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('\\') | P.char('\n'))).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
9 changes: 9 additions & 0 deletions core/src/test/scala/io/chrisdavenport/curly/MainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ 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'""".stripMargin
val actual = CurlyParser.all.parseAll(cmd)
assertEquals(actual.map(_.length), Right(4))
}

}