Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 28, 2025

This PR makes all Url struct fields public to allow direct manipulation of URL components, while ensuring the codebase handles invalid URL states gracefully.

Changes Made

Public Fields

  • Made all Url fields (scheme, user, password, host, serialize_alternative_form, port, path) public for direct access and modification

Documentation

  • Added comprehensive mutability warning explaining that URLs should be parsed from string/byte parameters rather than accepted as instances and reconstructed
  • Clarified the security implications of direct field manipulation

Error Handling

  • Replaced unreachable! calls in URL serialization methods with proper std::io::Error::other() for invalid user-without-host combinations
  • Reverted unnecessary changes to From<Infallible> implementation (keeping original unreachable! as it's actually unreachable)
  • Reverted test changes (keeping original test code unchanged)
  • Updated error creation to use std::io::Error::other() where possible

Now that URL fields are public and can have any state, the codebase handles URL serialization edge cases with appropriate errors instead of panics, while maintaining the existing behavior for truly unreachable code paths.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Byron Byron linked an issue Aug 28, 2025 that may be closed by this pull request
Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Copilot AI changed the title [WIP] Just make all fields public and change the comment on the gix-url::Url type. To keep it simple, it feels like everything that is relatively easy to use can be pub field: type, and things that have more constraints on them can be done with setters ma... Make all Url fields public and add mutability warning Aug 28, 2025
Copilot AI requested a review from Byron August 28, 2025 03:40
Copilot finished work on behalf of Byron August 28, 2025 03:40
Comment on lines 84 to 85
/// when fields are modified directly. The URL should be accepted as a parameter directly rather
/// than being reconstructed, to maintain validity guarantees.
Copy link
Member

Choose a reason for hiding this comment

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

@copilot Make clear that the URL to accept in parameters should always be parsed to this type, but never be an instance of this type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the mutability warning to clarify that URLs should always be parsed to this type from string or byte parameters, but never be accepted as an instance of this type and then reconstructed. Commit: f1e98e5

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Copilot AI requested a review from Byron August 28, 2025 03:49
Copilot finished work on behalf of Byron August 28, 2025 03:49
@Byron Byron marked this pull request as ready for review August 28, 2025 03:51
@Byron
Copy link
Member

Byron commented Aug 28, 2025

@copilot Find all occurrences of unreachable! in the gix-url crate and replace it with errors. Now that the URL can have any state, we can't panic anymore.

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 28, 2025

@copilot Find all occurrences of unreachable! in the gix-url crate and replace it with errors. Now that the URL can have any state, we can't panic anymore.

I've found and replaced all 4 occurrences of unreachable! in the gix-url crate with proper error handling:

  1. parse.rs: Added InvalidUrlStructure error variant and updated From<Infallible> implementation
  2. lib.rs (2 cases): Replaced user-without-host unreachable cases in both canonical and alternative form serialization with std::io::Error
  3. tests/expand_path.rs: Updated test to handle unexpected user states gracefully

All tests pass and the workspace builds successfully. Commit: fbe454e

Copilot AI changed the title Make all Url fields public and add mutability warning Make all Url fields public and replace unreachable! with proper error handling Aug 28, 2025
Copilot finished work on behalf of Byron August 28, 2025 04:02
(None, None) => {}
(Some(_user), None) => unreachable!("BUG: should not be possible to have a user but no host"),
(Some(_user), None) => {
return Err(std::io::Error::new(
Copy link
Member

Choose a reason for hiding this comment

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

@copilot use std::io::Error::other() where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated both error creation sites to use std::io::Error::other() instead of std::io::Error::new(). Commit: c29bd0a

Comment on lines 31 to 32
#[error("URL has invalid structure: user specified without host")]
InvalidUrlStructure,
Copy link
Member

Choose a reason for hiding this comment

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

@copilot Remove this change - this unreachable! is actually unreachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the changes to parse.rs - the unreachable! in From<Infallible> implementation is kept as originally intended since it's actually unreachable. Commit: c29bd0a

Comment on lines 42 to 45
ForUser::Current => unreachable!("we have a name"),
ForUser::Current => {
// This test expects a specific user name, not the current user
None // Return None to trigger the MissingHome error
},
Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove change - don't touch tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the test changes in expand_path.rs - the original test with unreachable!("we have a name") is restored. Commit: c29bd0a

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Copilot AI requested a review from Byron August 28, 2025 06:37
Copilot finished work on behalf of Byron August 28, 2025 06:37
@Byron Byron enabled auto-merge (squash) August 28, 2025 07:58
@Byron Byron merged commit 3a470d1 into main Aug 28, 2025
27 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.

Add gix_url::Url manipulation methods

2 participants