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

Sanitize URLs in file fields to handle invalid pipe characters ('|') #12156

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hitalo-siriano
Copy link

Closes #11876.

  • Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
  • Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
  • URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
  • Added test cases to URLUtilTest to verify correct sanitization and URL creation.

…loses JabRef#11876.

- Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
- Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
- URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
- Added test cases to URLUtilTest to verify correct sanitization and URL creation.
@hitalo-siriano
Copy link
Author

Am I on the right track to resolve this Issue?


public static URI createUri(String url) {
try {
String urlFormat = url.replace("|", "%7C");
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment explaining why we are doing this and the relevant references.

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

Add an Architecture Test disallowing the use of URI.create

try {
String urlFormat = url.replace("|", "%7C");
return new URI(urlFormat);
} catch (URISyntaxException e) {
Copy link
Member

Choose a reason for hiding this comment

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

Add @throws JavaDoc, too

@koppor
Copy link
Member

koppor commented Nov 11, 2024

@hitalo-siriano Are you still on it? The steps to finish it seem to be small.

@hitalo-siriano
Copy link
Author

@koppor Yes, I'm still working on the changes

hitalo-siriano and others added 2 commits November 16, 2024 14:18
…loses JabRef#11876.

- Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
- Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
- URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
- Added test cases to URLUtilTest to verify correct sanitization and URL creation.
- Added @archtest to ensure that the URI.create() method is not directly called in the codebase.
* @param url the URL string to be converted into a {@link URL}.
* @return the {@link URL} object created from the string URL.
* @throws MalformedURLException if the URL is malformed and cannot be converted to a {@link URL}.
*/

Copy link
Member

Choose a reason for hiding this comment

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

no empty line between JavaDoc and method

add an empty line above JavaDoc

Comment on lines 66 to 67
} catch (
MalformedURLException e) {
Copy link
Member

Choose a reason for hiding this comment

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

Remove empty line (we know that the IntelliJ autoformatter creates this - but no one invested significant time to fix this)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

…loses JabRef#11876.

- Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
- Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
- URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
- Added test cases to URLUtilTest to verify correct sanitization and URL creation.
- Added @archtest to ensure that the URI.create() method is not directly called in the codebase.
…loses JabRef#11876.

- Introduced URLUtil.createUri() and URLUtil.create() to handle URL sanitization.
- Replaced direct calls to URI.create() and URI.create().toURL() with the new utility methods.
- URLs containing the pipe character ('|') are now properly encoded as '%7C' to prevent parsing errors.
- Added test cases to URLUtilTest to verify correct sanitization and URL creation.
- Added @archtest to ensure that the URI.create() method is not directly called in the codebase.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

@hitalo-siriano
Copy link
Author

@koppor I made the requested changes, is there anything else that needs to be done?

@hitalo-siriano hitalo-siriano marked this pull request as ready for review November 17, 2024 02:57
@koppor
Copy link
Member

koppor commented Nov 17, 2024

@hitalo-siriano please see the automated output that your code misses matching our style rules. Fix that first. That reduces load on our side.

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.

Illegal character in query: pipe character in file field
3 participants