Skip to content

Make QueryParams#unsafeQueryParam return null for missing key (#3441) #3445

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

Merged
merged 1 commit into from
Apr 4, 2025

Conversation

987Nabil
Copy link
Contributor

@987Nabil 987Nabil commented Apr 2, 2025

fixes #3441

@987Nabil 987Nabil mentioned this pull request Apr 2, 2025
underlying.get(key).get(0)
override private[http] def unsafeQueryParam(key: String): String = {
val value = underlying.get(key)
if (value == null) null else value.get(0)
Copy link

Choose a reason for hiding this comment

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

given that this is a list, you are still open to throwing a null pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why? If it is null, I return null. If it is the empty list, get 0 returns null. That is the behaviour I want. Did I miss something?

Copy link

@mwalden mwalden Apr 3, 2025

Choose a reason for hiding this comment

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

sorry i meant that on value.get(0). we may want a check around that.
edit:
sorry did you say .get(0) would return null on an empty list? Wouldnt it return out of bounds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@mwalden
Copy link

mwalden commented Apr 2, 2025

there were tests in the initial PR that were closed. to be safe, we should probably include them too.

#3443

@987Nabil
Copy link
Contributor Author

987Nabil commented Apr 2, 2025

The tests already exists in the RoundtripSpec. It was green, because the value was added when it is encoded as null. Now it is not added, and without the fix in QueryParams it fails

@987Nabil 987Nabil force-pushed the fix-query-encoding-decodeing branch from c196f61 to b207c4d Compare April 4, 2025 09:42
@987Nabil 987Nabil merged commit 812e6c8 into zio:main Apr 4, 2025
38 checks passed
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.

when an Endpoints implements function with options will only be called when all options are present
3 participants