The Issue occurs when we add path segments delimited by '/' as part of the filtering mechanism, and HttpUrl treats them as a single, large path segment.
:pencil: Changes
I added methods to safely add skips_path.
Why not use HttpUrl::addPathSegments?
The problem with addPathSegments is that it replaces a leading '/' with an empty path segment, turning '/' into '//'. This causes issues for HttpUrl in general.
For example
Both MockWebServer::url and HttpUrl.Builder::resolve don't handle '//' segments properly.
private fun executeRequestForPath(
okHttpClient: OkHttpClient,
path: String,
responseBody: String,
) {
val httpUrl =
HttpUrl.Builder()
.scheme("https")
.host("testexample.com")
.addPathSegments(path)
.build()
val request = Request.Builder().url(server.url(httpUrl.encodedPath)).build()
server.enqueue(MockResponse().setBody(responseBody))
okHttpClient.newCall(request).execute().readByteStringBody()
}
:page_facing_up: Context
The Issue occurs when we add path segments delimited by '/' as part of the filtering mechanism, and HttpUrl treats them as a single, large path segment.
:pencil: Changes
I added methods to safely add skips_path.
Why not use HttpUrl::addPathSegments?
The problem with addPathSegments is that it replaces a leading '/' with an empty path segment, turning '/' into '//'. This causes issues for HttpUrl in general.
For example
Both MockWebServer::url and HttpUrl.Builder::resolve don't handle '//' segments properly.
I consider these results problematic for our tests as the logic is changed here.
Even if we found a workaround, user inputs would still be transformed from '/path/to/test' to '//path/to/test', which leads to unexpected behavior.
Comparison table for user input conversion using HttpUrl method and custom extension
Should we consider removing full URLs with hosts from tests, since there is a separate field for that purpose - 'skipDomain'?
:no_entry_sign: Breaking
Duplicated and empty path segments will be ignored once this change is applied.