Repository: square/okhttp
File: okhttp/src/commonTest/kotlin/okhttp3/WebPlatformToAsciiTest.kt (Kotlin)

Code before:

    // OkHttp rejects labels longer than 63 code points, the web platform tests don't.
    "x01234567890123456789012345678901234567890123456789012345678901x.xn--zca",
    "x01234567890123456789012345678901234567890123456789012345678901x.ß",
    "x01234567890123456789012345678901234567890123456789012345678901x",
    "x01234567890123456789012345678901234567890123456789012345678901†",

    // OkHttp rejects domain names longer than 253 code points, the web platform tests don't.
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x",
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--zca",
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.ß",

    // OkHttp does not reject invalid Punycode.
    "xn--a",
    "xn--a.xn--zca",
    "xn--a-yoc",

    // OkHttp doesn't reject U+FFFD encoded in Punycode.
    "xn--zn7c.com",

    // OkHttp doesn't reject a U+200D. https://www.rfc-editor.org/rfc/rfc5892.html#appendix-A.2
    "xn--1ug.example",
  )

  val knownFailuresJvm = commonKnownFailures + setOf(
    // OkHttp incorrectly does transitional processing, so it maps 'ß' to 'ss'
    "-x.ß",
    "ab--c.ß",
    "x-.ß",
    "xn--a.ß",
    "xn--zca.ß",
    "ශ්‍රී",

    // OkHttp does not reject invalid Punycode.
    "xn--",
    "xn--ls8h=",

    // OkHttp returns `xn--mgba3gch31f`, not `xn--mgba3gch31f060k`.
    "نامه‌ای",
  )

  val knownFailuresNonJvm = commonKnownFailures + setOf(
    // OkHttp doesn't reject this invalid punycode.
    "xn--a.ß",

    // OkHttp doesn't implement CheckJoiners.
    "\u200D.example",

    // OkHttp doesn't implement CheckBidi.
    "يa",
  )

Review comment (bug):
Yay! This is probably the bugfix with the most user impact

Code after:

    // OkHttp rejects labels longer than 63 code points, the web platform tests don't.
    "x01234567890123456789012345678901234567890123456789012345678901x.xn--zca",
    "x01234567890123456789012345678901234567890123456789012345678901x.ß",
    "x01234567890123456789012345678901234567890123456789012345678901x",
    "x01234567890123456789012345678901234567890123456789012345678901†",

    // OkHttp rejects domain names longer than 253 code points, the web platform tests don't.
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x",
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--zca",
    "01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.ß",

    // OkHttp does not reject invalid Punycode.
    "xn--a",
    "xn--a.ß",
    "xn--a.xn--zca",
    "xn--a-yoc",

    // OkHttp doesn't reject U+FFFD encoded in Punycode.
    "xn--zn7c.com",

    // OkHttp doesn't reject a U+200D. https://www.rfc-editor.org/rfc/rfc5892.html#appendix-A.2
    "xn--1ug.example",

    // OkHttp doesn't implement CheckJoiners.
    "\u200D.example",

    // OkHttp doesn't implement CheckBidi.
    "يa",
  )

  @Test
  fun test() {
    val list = WebPlatformToAsciiData.load()
    val failures = mutableListOf<Throwable>()
    for (entry in list) {
      var failure: Throwable? = null
      try {
        testToAscii(entry.input!!, entry.output, entry.comment)
      } catch (e: Throwable) {
        failure = e
      }

      if (entry.input in knownFailures) {
        if (failure == null) failures += AssertionError("known failure didn't fail: $entry")
      } else {
        if (failure != null) failures += failure
      }
    }

    if (failures.isNotEmpty()) {