Skip to content

Conversation

karenetheridge
Copy link
Contributor

Summary

Treats $query->parse(undef) the same as $query->parse('')

Motivation

This allows for $uri->query(undef) to properly clear the query string, which previously did not happen if the parameters object had already been parsed into pairs.

This usage might be seen with $uri->query(undef)->fragment(undef) to strip off all trailing components after the path.

This allows for $uri->query(undef) to properly clear the query string, rather
than leaving the previous value of 'pairs' intact
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the behavior of Mojo::Parameters so that passing undef to parse clears the query string, aligning with user expectations when using $uri->query(undef).

  • Adds new tests to assert that undef leads to an empty query string and empty pairs list.
  • Updates the parse method to coerce undef into an empty string using the defined-or operator.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
t/mojo/parameters.t Adds tests for proper handling of undef in query parsing.
lib/Mojo/Parameters.pm Modifies the parse method to treat undef as an empty string.
Comments suppressed due to low confidence (2)

t/mojo/parameters.t:184

  • [nitpick] The new test case verifies that passing undef clears both the query string and pairs list. Consider adding an additional test for the scenario where the parameters are already empty to further ensure consistency.
$params->parse(undef);

lib/Mojo/Parameters.pm:113

  • [nitpick] The use of the defined-or (//) operator is a clean approach to handle undefined values. Verify that any related logic in the module correctly handles an empty string resulting from this change.
$self->{string} = shift // '';

karenetheridge added a commit to karenetheridge/OpenAPI-Modern that referenced this pull request Jun 15, 2025
Copy link
Member

@christopherraa christopherraa left a comment

Choose a reason for hiding this comment

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

👍

@mergify mergify bot merged commit 75508c2 into mojolicious:main Jun 16, 2025
11 checks passed
@karenetheridge karenetheridge deleted the ether/undef-url-query branch June 16, 2025 17:28
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.

3 participants