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

Solution: method skipPaths on builder does not work as expected, issue #1237 #1290

Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Please add your entries according to this format.
* Kotlin to 2.0.20
* AGP to 8.5.2
* Fix Toolbar is not accessible on api level 35 [#1280]
* Fixed the `skipPaths` method unexpectedly modified the passed arguments [#1237]

### Added
* Added _save as text_ and _save as .har file_ options to save all transactions [#1214]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.chuckerteam.chucker.internal.support.CacheDirectoryProvider
import com.chuckerteam.chucker.internal.support.PlainTextDecoder
import com.chuckerteam.chucker.internal.support.RequestProcessor
import com.chuckerteam.chucker.internal.support.ResponseProcessor
import com.chuckerteam.chucker.internal.support.addNonBlankPathSegments
import okhttp3.HttpUrl
import okhttp3.Interceptor
import okhttp3.Response
Expand Down Expand Up @@ -199,6 +200,9 @@ public class ChuckerInterceptor private constructor(
/**
* Sets a list of [String] to skip paths. When any of the [String] matches
* a request path, the request will be skipped.
*
* **Note:** An empty path will be treated as the '/'.
* '//' will also be treated as the '/' path.
*/
public fun skipPaths(vararg paths: String): Builder =
apply {
Expand All @@ -207,7 +211,8 @@ public class ChuckerInterceptor private constructor(
HttpUrl.Builder()
.scheme("https")
.host("example.com")
.addPathSegment(candidatePath).build()
.addNonBlankPathSegments(candidatePath)
.build()
[email protected](httpUrl.encodedPath)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.chuckerteam.chucker.internal.support

import okhttp3.HttpUrl

private const val PATH_SEGMENTS_DELIMITER = "/"

public fun HttpUrl.Builder.addNonBlankPathSegments(candidatePath: String): HttpUrl.Builder =
apply {
candidatePath.split(PATH_SEGMENTS_DELIMITER).filter { it.isNotBlank() }
.forEach { item -> addPathSegment(item) }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chuckerteam.chucker.api

import com.chuckerteam.chucker.internal.support.addNonBlankPathSegments
import com.chuckerteam.chucker.util.ChuckerInterceptorDelegate
import com.chuckerteam.chucker.util.ClientFactory
import com.chuckerteam.chucker.util.NoLoggerRule
Expand Down Expand Up @@ -379,7 +380,11 @@ internal class ChuckerInterceptorSkipRequestTest {
responseBody: String,
) {
val httpUrl =
HttpUrl.Builder().scheme("https").host("testexample.com").addPathSegment(path).build()
HttpUrl.Builder()
.scheme("https")
.host("testexample.com")
.addNonBlankPathSegments(path)
.build()

val request = Request.Builder().url(server.url(httpUrl.encodedPath)).build()
server.enqueue(MockResponse().setBody(responseBody))
Expand Down
Loading