Skip to content

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

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

Merged
merged 21 commits into from
Nov 25, 2024

Conversation

ghost
Copy link

@ghost ghost commented Nov 5, 2024

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 #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.
@ghost
Copy link
Author

ghost commented Nov 5, 2024

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.

@ghost
Copy link
Author

ghost commented Nov 12, 2024

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

brasilnovo and others added 2 commits November 16, 2024 14:18
…loses #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 #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 #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.

@ghost
Copy link
Author

ghost commented Nov 17, 2024

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

@ghost ghost 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.

@koppor koppor self-assigned this Nov 25, 2024
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 OpenRewrite to ensure "modern" Java coding practices.
The issues found can be automatically fixed.
Please execute the gradle task rewriteRun, check the results, commit, and push.

You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".

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.

@koppor koppor added this pull request to the merge queue Nov 25, 2024
Merged via the queue into JabRef:main with commit 861a6ce Nov 25, 2024
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