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

Allow non-RFC 3986-compliant URLs #45

Merged
merged 2 commits into from
Nov 1, 2023
Merged

Conversation

c960657
Copy link
Contributor

@c960657 c960657 commented Oct 12, 2023

This PR has objective as #44 but takes a different approach.

It avoids polymorphism. It still represents URLs as URI instances but uses a very liberal URL parser.

Copy link
Member

@knu knu left a comment

Choose a reason for hiding this comment

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

Thanks. I'm not confident that the parser can be this loose, so I'd like to change it to a bit more conservative implementation with which the specs you provided will pass.


REGEXP = {
ABS_PATH: /\A[^?#]*\z/
}
Copy link
Member

Choose a reason for hiding this comment

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

This constant does not seem to be used in any way.

if uri.is_a?(URI::Generic)
uri
elsif uri = String.try_convert(uri)
parse(uri)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should try the default URI.parse() first and then our custom parser only if it fails.

Comment on lines +1 to +4
require 'singleton'

class HTTP::Cookie::URIParser
include Singleton
Copy link
Member

Choose a reason for hiding this comment

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

You don't need a class or instance for providing these methods. Make it a module and provide module functions.

Suggested change
require 'singleton'
class HTTP::Cookie::URIParser
include Singleton
module HTTP::Cookie::URIParser
module_function

}

def parse(uri)
m = /
Copy link
Member

Choose a reason for hiding this comment

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

Using %r{…} will eliminate the need for escaping the slash character.

@knu knu merged commit 27cc46c into sparklemotion:master Nov 1, 2023
@knu
Copy link
Member

knu commented Nov 1, 2023

@c960657 Check out 043d653 and let me know if it doesn't meet your needs.

@c960657
Copy link
Contributor Author

c960657 commented Nov 2, 2023

Yes, I believe it does. Thanks!

@jesseclark
Copy link

@knu This solution solved some of the errors I saw but also some invalid URIs with curly braces in path segments. Would you be open to adding curly braces to the gsub regexp in #escape_path?

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