Repository: square/okhttp
File: okhttp/src/jvmMain/kotlin/okhttp3/Cookie.kt (Kotlin)

Code before:
      this.domain = canonicalDomain
      this.hostOnly = hostOnly
    }

    fun path(path: String) = apply {
      require(path.startsWith("/")) { "path must start with '/'" }
      this.path = path
    }

    fun secure() = apply {
      this.secure = true
    }

    fun httpOnly() = apply {
      this.httpOnly = true
    }

    fun sameSite(sameSite: String) = apply {
      require(sameSite.trim() == sameSite) { "sameSite is not trimmed" }
      this.sameSite = sameSite
    }

    fun build(): Cookie {
      if (sameSite.equals("None", ignoreCase = true)) {
        require(secure) { "Secure attribute is required for this SameSite policy" }
      }

      return Cookie(
        name ?: throw NullPointerException("builder.name == null"),
        value ?: throw NullPointerException("builder.value == null"),
        expiresAt,
        domain ?: throw NullPointerException("builder.domain == null"),
        path,
        secure,
        httpOnly,
        persistent,
        hostOnly,
        sameSite
      )
    }
  }

  @Suppress("NAME_SHADOWING")
  companion object {
    private val YEAR_PATTERN = Pattern.compile("(\\d{2,4})[^\\d]*")
    private val MONTH_PATTERN =
      Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*")
    private val DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d{1,2})[^\\d]*")
    private val TIME_PATTERN = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*")

    private fun domainMatch(urlHost: String, domain: String): Boolean {

Review comment (suggestion):
```suggestion
```

I’m anxious about this 'cause I’d like this to work for all cookies:

```kotlin
val cookie: Cookie = ...
val copy = cookie.newBuilder().build()
```

In this case we’re strict on `build()` in a way that we can’t / shouldn’t be on `parse()`.

Code after:
      this.domain = canonicalDomain
      this.hostOnly = hostOnly
    }

    fun path(path: String) = apply {
      require(path.startsWith("/")) { "path must start with '/'" }
      this.path = path
    }

    fun secure() = apply {
      this.secure = true
    }

    fun httpOnly() = apply {
      this.httpOnly = true
    }

    fun sameSite(sameSite: String) = apply {
      require(sameSite.trim() == sameSite) { "sameSite is not trimmed" }
      this.sameSite = sameSite
    }

    fun build(): Cookie {

      return Cookie(
        name ?: throw NullPointerException("builder.name == null"),
        value ?: throw NullPointerException("builder.value == null"),
        expiresAt,
        domain ?: throw NullPointerException("builder.domain == null"),
        path,
        secure,
        httpOnly,
        persistent,
        hostOnly,
        sameSite
      )
    }
  }

  @Suppress("NAME_SHADOWING")
  companion object {
    private val YEAR_PATTERN = Pattern.compile("(\\d{2,4})[^\\d]*")
    private val MONTH_PATTERN =
      Pattern.compile("(?i)(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec).*")
    private val DAY_OF_MONTH_PATTERN = Pattern.compile("(\\d{1,2})[^\\d]*")
    private val TIME_PATTERN = Pattern.compile("(\\d{1,2}):(\\d{1,2}):(\\d{1,2})[^\\d]*")

    private fun domainMatch(urlHost: String, domain: String): Boolean {
      if (urlHost == domain) {
        return true // As in 'example.com' matching 'example.com'.
      }