Skip to content

Conversation

Muskan244
Copy link
Contributor

@Muskan244 Muskan244 commented Jul 18, 2025

Closes #12995

This PR to make FileUtil.relativize symlink-aware by:

  • Updating FileUtil::relativize to handle symlinks when resolving relative paths.

  • Ensuring files inside symlinked directories are correctly referenced by their relative path.

  • Adding unit tests to verify correct behavior with symlinked and regular directories.

  • Adding ignored test for symlink escape scenario (/lib/things -> /share/expensive -> /veryprivate).

Steps to test

  • Build JabRef and run the full test suite:
    Gradle: ./gradlew test
    Ensure all tests in FileUtilTest related to symlink handling pass without errors.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [/] Screenshots added in PR description (if change is visible to the user)
  • [/] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [/] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Muskan244 and others added 13 commits July 8, 2025 13:23
…ion and OpenSelectedEntriesFilesAction

- Introduced OpenSingleExternalFileAction to handle single entry with one linked file
- Introduced OpenSelectedEntriesFilesAction to handle multiple selection cases

Fixes JabRef#13431
…13505)

Bumps [org.junit.platform:junit-platform-launcher](https://github.com/junit-team/junit-framework) from 1.13.1 to 1.13.3.
- [Release notes](https://github.com/junit-team/junit-framework/releases)
- [Commits](https://github.com/junit-team/junit-framework/commits)

---
updated-dependencies:
- dependency-name: org.junit.platform:junit-platform-launcher
  dependency-version: 1.13.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
…resolution

- Use real/canonical paths to ensure files are correctly recognized as within a directory, even through symlinks
- Add and document unit tests covering symlinked and normal directory scenarios
fixes JabRef#12995
@Muskan244 Muskan244 closed this Jul 18, 2025
@Muskan244 Muskan244 deleted the fix-for-issue-12995 branch July 18, 2025 09:54
@Muskan244 Muskan244 restored the fix-for-issue-12995 branch July 18, 2025 09:55
@Muskan244 Muskan244 reopened this Jul 19, 2025
@Muskan244
Copy link
Contributor Author

Hi! I’ve pushed the requested changes, and it looks like all checks have passed. Just checking in to see if there's anything more I should do. Thanks again for guiding me through this!

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.

I don't see a test I've put in the issue description.

I am not sture if the algorithm works. I am not sure how symlinks are really ersolved on Linux on edge cases.

… simplicity, and ensured all edge cases from issue JabRef#12995 are now covered.
@koppor
Copy link
Member

koppor commented Aug 17, 2025

Note that there is no test for #12995 (comment) - it would be OK to have it ignored. Not sure how important this is, but it should be noted down somewhere. Maybe a link js enough.

@Muskan244
Copy link
Contributor Author

Hi @koppor, Do you suggest we add this as an ignored test and just link to your comment in #12995, or, try to change FileUtil.relativize to explicitly detect and prevent such escapes? Just want to be sure.

@koppor
Copy link
Member

koppor commented Aug 18, 2025

Hi @koppor, Do you suggest we add this as an ignored test and just link to your comment in #12995, or, try to change FileUtil.relativize to explicitly detect and prevent such escapes? Just want to be sure.

The former is enough.

@koppor
Copy link
Member

koppor commented Aug 19, 2025

I used RefactoringMiner to review

The logic diff is as follows

image

And test case

image

There were some syntax changes; I try to look. Refs JabRef#672.

@koppor
Copy link
Member

koppor commented Aug 19, 2025

@Muskan244 Why didn't you add a CHANGELOG.md entry?!

Comment on lines 279 to 285
private static Optional<Path> tryRealPath(Path path) {
if (Files.exists(path)) {
try {
return Optional.of(path.toRealPath());
} catch (IOException e) {
return Optional.empty();
}
Copy link

Choose a reason for hiding this comment

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

The method catches IOException and returns Optional.empty() instead of letting the exception propagate. This uses exceptions for control flow which is against best practices.

@koppor koppor enabled auto-merge August 19, 2025 13:10
Copy link

trag-bot bot commented Aug 19, 2025

@trag-bot didn't find any issues in the code! ✅✨

@koppor koppor added this pull request to the merge queue Aug 19, 2025
Merged via the queue into JabRef:main with commit d06248f Aug 19, 2025
1 check passed
@koppor
Copy link
Member

koppor commented Aug 19, 2025

Follow-up would be to spleit the parameterized test into seperate test cases - the method producing the arguments is not very readable.

@Muskan244
Copy link
Contributor Author

Thanks! I’ll prepare a follow-up PR for splitting the parameterized test into separate test cases to make it more readable.

Siedlerchr added a commit that referenced this pull request Aug 21, 2025
* upstream/main:
  New translations jabref_en.properties (Italian) (#13725)
  Minor code style updates (#13722)
  Fix: Make FileUtil.relativize symlink-aware (#13553)
  New Crowdin updates (#13720)
  Bump org.glassfish.jersey.core:jersey-server in /versions (#13714)
  Enable UseObjectNotifyAll (#13718)
  Bump com.dlsc.gemsfx:gemsfx from 3.3.5 to 3.4.2 in /versions (#13717)
  Update on-issue-comment.yml
  Bump org.openrewrite.recipe:rewrite-recipe-bom from 3.12.1 to 3.13.0 (#13716)
  Bump org.openrewrite.rewrite from 7.12.1 to 7.14.0 (#13715)
  Bump org.glassfish.jersey.inject:jersey-hk2 in /versions (#13713)
  feat(git): add “Share to GitHub” flow (#13677)
  Bump jablib/src/main/resources/csl-styles from `292aec3` to `1194364` (#13712)
  Bump jablib/src/main/abbrv.jabref.org from `cfe719f` to `a97f9c6` (#13711)
  Bump jablib/src/main/resources/csl-locales from `e2de1e3` to `fa56de1` (#13710)
  Add noop Git Config System Reader to prevent usage of real world stuff into jgit (#13703)
  Added static (stream & preferences) constructors to BibDatabaseContext (#13694)
  New Crowdin updates (#13698)
  fix git modules requires and uses (#13696)
  Focus "Specify Bib(La)TeX" when Bib(La)TeX is in clipboard (#13633)
@Muskan244 Muskan244 deleted the fix-for-issue-12995 branch August 28, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileUtil::relativize doesn't take symlinks into account

3 participants