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

Add uri_encode function (#273) #285

Closed
wants to merge 1 commit into from
Closed

Conversation

dr0i
Copy link
Member

@dr0i dr0i commented Feb 17, 2023

Resolves #273.

Copy link
Member

@fsteeg fsteeg left a comment

Choose a reason for hiding this comment

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

Added one inline comment on the encoding implementation.

We'd also have to add documentation on the new function in the README.

};

private static final PercentEscaper PERCENT_ESCAPER = new PercentEscaper("", false);
Copy link
Member

Choose a reason for hiding this comment

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

From what I understood, the conclusion from #273 was to basically use the metamorph implementation, which uses java.net.URLEncoder. If there is no specific reason for using PercentEscaper here, I think using the standard Java class would be preferable.

Copy link
Member Author

@dr0i dr0i Feb 23, 2023

Choose a reason for hiding this comment

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

java.net.URLEncoder does not conform to RFC 3986.
Also, we want to conform to catmandu fix' uri_encode. Perl does it right , see https://metacpan.org/pod/URI::Encode.

Copy link
Member Author

@dr0i dr0i Feb 23, 2023

Choose a reason for hiding this comment

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

In lobid-resources I added a UrlEscaper which also complies to RFC 3986, using an older com.google.gdata.util.common.base.PercentEscaper. It hasn't make it to metafacture (yet).

@blackwinter
Copy link
Member

In general, I would prefer to use the Metamorph implementation directly (see e.g. #230 and #231). If it doesn't provide a suitable interface it should be added there and then reused for both. Eventually, org.metafacture.metamorph.functions might be generalized and moved to org.metafacture.commons.functions (or something like that).

@dr0i
Copy link
Member Author

dr0i commented Feb 23, 2023

In general, I would prefer to use the Metamorph implementation directly

good point. Agreed. Awaiting ok for using percent encoder and then migrate function to metafcature-core.

We'd also have to add documentation on the new function in the README.

Right - forgot about that. Would do this also im metfacture-core. Will note the RFC 3986 compliance there.

@fsteeg
Copy link
Member

fsteeg commented Feb 23, 2023

One thing leading to confusion here (at least for me) is that we actually need something to encode a string to be used in a URI (in particular as a path segment), not to encode a full URI. So for http://perl.com/foo bar we don't want http://perl.com/foo%20bar (which would be a valid URI), but we want http%3A%2F%2Fperl.com%2Ffoo%20bar (which can be used as a path segment in a URI, but is not itself a valid URI).

Now if I understand it correctly, both metamorph.functions.URLEncode and Catmandu::Fix::uri_encode basically do that, but Java's URLEncoder (which is currently used in metamorph.functions.URLEncode) uses + instead of %20 for blanks, which is a problem for using it in lobid-resources.

To both avoid breaking the current metamorph.functions.URLEncode behavior and reusing as much implementation as possible, this is what @dr0i and I just discussed: we could base metamorph.functions.URLEncode on PercentEscaper, with an option to pass the safeChars config. In the default used in metamorph, we use SAFECHARS_URLENCODER, which "mimics the behavior of java.net.URLEncoder" (thus no break), and in metafix we use e.g. SAFE_PLUS_RESERVED_CHARS_URLENCODER (to get what we need in lobid-resources and be consistent with Catmandu::Fix::uri_encode).

@fsteeg fsteeg removed their assignment Feb 23, 2023
Copy link
Member

@blackwinter blackwinter left a comment

Choose a reason for hiding this comment

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

Agreed. For increased flexibility the safeChars option should be exposed to Fix and Morph.

@dr0i
Copy link
Member Author

dr0i commented Jun 16, 2023

This PR is substituted by #314.
Closing.

@dr0i dr0i closed this Jun 16, 2023
@dr0i dr0i deleted the 273-implementUriEncodeFunction branch June 16, 2023 15:34
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 function to percent-encode strings
3 participants