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 ScalaJS regex and regression tests #2912

Merged
merged 1 commit into from
Jun 18, 2024
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
67 changes: 67 additions & 0 deletions zio-http/js/src/test/scala/zio/http/RegexSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package zio.http

import zio._
import zio.test._

object RegexSpec extends ZIOSpecDefault {
override def spec: Spec[TestEnvironment with Scope, Any] =
suite("RegexSpec")(
suite("Header")(
test("AcceptLanguage") {
ZIO.succeed(Header.AcceptLanguage).isSuccess.map(s => assertTrue(s))
},
test("ContentDisposition") {
ZIO.succeed(Header.ContentDisposition).isSuccess.map(s => assertTrue(s))
},
test("ContentMd5") {
ZIO.succeed(Header.ContentMd5).isSuccess.map(s => assertTrue(s))
},
test("ContentRange") {
ZIO.succeed(Header.ContentRange).isSuccess.map(s => assertTrue(s))
},
test("ContentSecurityPolicy.Source") {
ZIO.succeed(Header.ContentSecurityPolicy.Source).isSuccess.map(s => assertTrue(s))
},
test("ContentSecurityPolicy.TrustedTypesValue") {
ZIO.succeed(Header.ContentSecurityPolicy.TrustedTypesValue).isSuccess.map(s => assertTrue(s))
},
test("ContentSecurityPolicy") {
ZIO.succeed(Header.ContentSecurityPolicy).isSuccess.map(s => assertTrue(s))
},
test("ContentTransferEncoding") {
ZIO.succeed(Header.ContentTransferEncoding).isSuccess.map(s => assertTrue(s))
},
test("From") {
ZIO.succeed(Header.From).isSuccess.map(s => assertTrue(s))
},
test("Trailer") {
ZIO.succeed(Header.Trailer).isSuccess.map(s => assertTrue(s))
},
test("UserAgent") {
ZIO.succeed(Header.UserAgent).isSuccess.map(s => assertTrue(s))
},
test("WWWAuthenticate") {
ZIO.succeed(Header.WWWAuthenticate).isSuccess.map(s => assertTrue(s))
},
test("WWWAuthenticate") {
ZIO.succeed(Header.WWWAuthenticate).isSuccess.map(s => assertTrue(s))
},
),
suite("HttpContentCodec")(
test("HttpContentCodec") {
ZIO.succeed(codec.HttpContentCodec).isSuccess.map(s => assertTrue(s))
},
),
suite("OpenAPI")(
test("Key") {
ZIO.succeed(endpoint.openapi.OpenAPI.Key).isSuccess.map(s => assertTrue(s))
},
test("Path") {
ZIO.succeed(endpoint.openapi.OpenAPI.Path).isSuccess.map(s => assertTrue(s))
},
test("LiteralOrExpression") {
ZIO.succeed(endpoint.openapi.OpenAPI.LiteralOrExpression).isSuccess.map(s => assertTrue(s))
},
),
)
}
6 changes: 3 additions & 3 deletions zio-http/shared/src/main/scala/zio/http/Header.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4149,9 +4149,9 @@ object Header {

final case class Comment(comment: String) extends UserAgent

private val productRegex = """(?i)([a-z0-9]+)(?:/([a-z0-9.]+))?""".r
private val commentRegex = """(?i)\((.*)$""".r
private val completeRegex = s"""^(?i)([a-z0-9]+)(?:/([a-z0-9.]+))(.*)$$""".r
private val productRegex = "(?i)([a-z0-9]+)(?:/([a-z0-9.]+))?".r
private val commentRegex = """(?i)\((.*)""".r
private val completeRegex = "(?i)([a-z0-9]+)(?:/([a-z0-9.]+))(.*)".r

def parse(userAgent: String): Either[String, UserAgent] = {
userAgent match {
Expand Down
Loading