Skip to content

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

Merged
cortinico merged 3 commits intoChuckerTeam:mainfrom
Ridje:bugfix/skip_path_add_segments_properly
Oct 4, 2024
Merged

Solution: method skipPaths on builder does not work as expected, issue #1237#1290
cortinico merged 3 commits intoChuckerTeam:mainfrom
Ridje:bugfix/skip_path_add_segments_properly

Conversation

@Ridje
Copy link
Copy Markdown
Contributor

@Ridje Ridje commented Oct 3, 2024

📄 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.

📝 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()
  }
Path request.url
"" http://localhost:52347/
" " http://localhost:52347/%20%20%20%20
"/skip/path" http://skip/path
"//skip//path" http://skip//path

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

User filter with HttpUrl::addPathSegments with addNonBlankPathSegments
"" / /
" " /%20%20%20%20
"example" /example /example
"www.example.com/skip/path" /www.example.com/skip/path /www.example.com/skip/path
"example.com/skip/path" /example.com/skip/path /example.com/skip/path
"90" /90 /90
"https://example/" /https://example/ /https:/example
"/skip/path" //skip/path /skip/path
"/skip//" //skip// /skip
"http://localhost:8080/skip/path/ext" /http://localhost:8080/skip/path/ext /http:/localhost:8080/skip/path/ext
"//skip//path" ///skip//path// /skip/path

Should we consider removing full URLs with hosts from tests, since there is a separate field for that purpose - 'skipDomain'?

🚫 Breaking

Duplicated and empty path segments will be ignored once this change is applied.

@Ridje Ridje requested a review from a team as a code owner October 3, 2024 13:38
@Ridje Ridje changed the title Changed way to add path segments. Solution: method skipPaths on builder does not work as expected, issue #1180 Oct 3, 2024
Copy link
Copy Markdown
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Thank you 🙏 Can you also update the CHANGELOG.md file @Ridje

@Ridje Ridje changed the title Solution: method skipPaths on builder does not work as expected, issue #1180 Solution: method skipPaths on builder does not work as expected, issue #1237 Oct 4, 2024
@Ridje
Copy link
Copy Markdown
Contributor Author

Ridje commented Oct 4, 2024

Updated:

  1. Modified commentary.
  2. Updated CHANGELOG.MD and listed this fix in it.

@cortinico cortinico enabled auto-merge (squash) October 4, 2024 13:01
@cortinico cortinico merged commit 6031c4c into ChuckerTeam:main Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants