Skip to content

Remove query and fragment from doi.org links when parsing DOIs - #17713

Merged
subhramit merged 11 commits into
JabRef:mainfrom
AnishKmSingh:fix-17689-doi-tracking-parameters
Nov 9, 2026
Merged

subhramit merged 11 commits into
JabRef:mainfrom
AnishKmSingh:fix-17689-doi-tracking-parameters

Conversation

@AnishKmSingh

Copy link
Copy Markdown
Contributor

Summary

When the DOI field contained a doi.org link with tracking parameters (eg. ?utm_source=newsletter) so "Copy DOI URL" kept them as part of DOI , encoded the ? as %3F and so it produce a broken link ("DOI NOT FOUND"). Now DOI.parse() removes the query and fragment from doi.org URLs before decoding so now the copied link is clean and open the Article.

I only do this for doi.org/ dx.doi.org links , because some other sites put the DOI inside the query (like Link.aspx?doi=10.5520/...). I also do it before decoding because an encoded %3F can be a real part of DOI and should stay.
This also helps other features that uses DOI.parse() like opening the DOI link and DOI cleanup.

Steps to test

  1. Start JabRef and create a new library using File -> New Library.
  2. Add a new Entry with (+) icon of type Article
  3. in the entry editor open Main->Identifiers and set the DOI field to: https://doi.org/10.1371/journal.pone.0000308?utm_source=newsletter.
  4. In the entry table right click the entry and choose Copy-> Copy DOI URL.
  5. Paste Copied link into a browser.

Expected: the copied link is https://doi.org/10.1371/journal.pone.0000308?utm_source=newsletter and the article opens.

Before fix:
Before_Doi_issue
Before_doi_issue_photo2

After fix:
After-fix-01

after_fix02

Related issues and pull requests

Closes #17689

AI usage

I used Claude(claude-opus-5.5) to understand the issue clearly and DOI parsing code to find the root cause and to draft changes and tests. Claude also pointed out the two edge cases (DOI inside the query of non-doi.org URLs and encoded %3F being part of real DOI).
I reproduce the bug myself went though every change until I understood why it needed applied changes in my local checkout , resolved the rebase conflict , ran DOITest and URLUtilTest locally and manually tested the fix in running JabRef(ScreenShot above). I take full ownership of code and can explain any part of it.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@jabref-machine jabref-machine added the dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) label Nov 5, 2026
@github-actions github-actions Bot added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Nov 5, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Strip query and fragment from doi.org links when parsing DOIs

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Remove query strings and fragments from doi.org resolver links so copied DOI URLs resolve
 correctly.
• Preserve DOIs in other sites’ query strings and encoded DOI characters.
• Add parsing tests and document the user-visible fix.
Diagram

graph TD
  A["Copy DOI URL"] --> B["DOI.parse"] --> C{"Resolver URL?"}
  C -->|yes| D["Strip query fragment"] --> F["Decode DOI"] --> G["Clean DOI URL"]
  C -->|no| E["Preserve input"] --> F
Loading
High-Level Assessment

The shared parsing entry point is the right place for this fix: copying and opening DOI links both use it. Restricting stripping to resolver URLs and doing it before decoding preserves DOIs carried in other sites’ queries and encoded DOI characters. A general URL parser was considered but adds complexity for input the DOI parser already accepts.

Files changed (5) +60 / -1

Bug fix (2) +31 / -1
URLUtil.javaAdd a query-and-fragment removal helper +15/-0

Add a query-and-fragment removal helper

• Adds a utility that removes a URL suffix beginning at the first literal question mark or hash. DOI parsing uses it before URL decoding.

jablib/src/main/java/org/jabref/logic/util/URLUtil.java

DOI.javaClean doi.org resolver links before decoding +16/-1

Clean doi.org resolver links before decoding

• DOI.parse now removes query strings and fragments from recognized doi.org resolver URLs. It leaves other inputs untouched so query-carried DOIs and encoded DOI characters remain parseable.

jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java

Tests (2) +28 / -0
URLUtilTest.javaTest URL suffix removal +11/-0

Test URL suffix removal

• Covers queries, fragments, both together, and URLs without either suffix.

jablib/src/test/java/org/jabref/logic/net/URLUtilTest.java

DOITest.javaTest resolver-link parsing and preservation cases +17/-0

Test resolver-link parsing and preservation cases

• Covers tracking parameters, fragments, dx.doi.org, short DOIs, and an encoded question mark. Also verifies that a DOI in a non-resolver URL’s query remains parseable.

jablib/src/test/java/org/jabref/model/entry/identifier/DOITest.java

Documentation (1) +1 / -0
CHANGELOG.mdDocument the Copy DOI URL fix +1/-0

Document the Copy DOI URL fix

• Adds a user-facing note about tracking parameters producing broken copied DOI links.

CHANGELOG.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (5)

Grey Divider


Action required

1. Cleanup truncates encoded DOI suffixes 🐞 Bug
Description
DoiCleanup.cleanup decodes the DOI field before passing it to DOI.parse, so the new
removeTrackingParameters call treats an encoded %3F in a resolver URL as a raw query delimiter.
Cleaning a stored value such as https://doi.org/10.1006/rwei.1999%3F.0001 therefore writes
10.1006/rwei.1999 back to the entry, even though direct parsing preserves the full DOI.
Code

jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[163]

+            String cleanedDOI = removeTrackingParameters(doi);
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
DOI cleanup decodes a stored resolver URL before `DOI.parse` can distinguish an encoded DOI character from a raw query delimiter, truncating the DOI written to the entry.
## Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/cleanup/DoiCleanup.java[39-61]
- jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[160-165]
## Recommended Fix
Pass the original DOI field value to `DOI.parse` so tracking removal precedes URL decoding, while retaining cleanup's existing formatting behavior. Add a cleanup regression test using a resolver URL with `%3F` in its DOI suffix.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Spaced DOI links retain tracking tags 🐞 Bug
Description
removeTrackingParameters trims only the ends of the input before matching a literal resolver URL,
while DOI.parse removes interior whitespace afterward. For an accepted input such as `https : / /
doi.org / 10.1000/foo?utm_source=x`, the tracking suffix remains in the parsed DOI and is encoded
into the copied URL.
Code

jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[R237-239]

+        String trimmed = doi.trim();
+        if (DOI_RESOLVER_LINK.matcher(trimmed).find()) {
+            return URLUtil.removeQueryAndFragment(trimmed);
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Whitespace within a resolver URL prevents tracking-parameter removal, even though DOI parsing later removes that whitespace and accepts the URL.
## Fix Focus Areas
- jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[163-168]
- jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[236-242]
## Recommended Fix
Normalize supported interior whitespace before testing for a resolver URL and removing its query or fragment, but keep removal before URL decoding so encoded DOI delimiters remain intact. Add a parsing test for a spaced resolver URL with tracking parameters.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View medium (2)
3. DOIs containing a raw ? or # get truncated 🐞 Bug
Description
removeTrackingParameters strips everything from the first ? or # in any doi.org or dx.doi.org
URL, so a DOI whose suffix legitimately contains a raw ? or # (valid in DOI names, and only
ambiguous in URLs) is silently cut short. Because DOI.parse feeds DoiCleanup, the fetchers and the
importers, the truncated DOI can be written back into the user's entry and then resolve to the wrong
or no article.
Code

jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[R236-237]

+        if (DOI_RESOLVER_PREFIX.matcher(trimmed).find()) {
+            return URLUtil.removeQueryAndFragment(trimmed);
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
In `DOI.removeTrackingParameters` (jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java, lines 234-240), every raw `?` or `#` in a doi.org URL is treated as the start of a query or fragment. DOIs may legitimately contain these characters, so the DOI is truncated and written back by DoiCleanup and other callers.
Fix Focus Areas
- jablib/src/main/java/org/jabref/model/entry/identifier/DOI.java[234-240]
- jablib/src/main/java/org/jabref/logic/util/URLUtil.java[27-29]
Recommended Fix
Decide the strip behaviour on a stronger signal, for example: keep the DOI unchanged when the stripped result would not match EXACT_DOI_PATT, or only strip the query when the text after `?`/`#` looks like a tracking-style `key=value` list. Add unit tests in DOITest for a DOI with a raw `?` or `#` in its suffix, asserting it is preserved.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Citation data bumps ship with DOI fix 🐞 Bug
Description
The PR moves three submodule pointers (abbrv.jabref.org, csl-locales, csl-styles) to new commits
that have no connection to DOI parsing or the tracking-parameter fix. Any regression those upstream
changes introduce to citation styles, locales, or journal abbreviations would merge with this fix
and be attributed to it.
Code

jablib/src/main/resources/csl-styles[1]

+Subproject commit 89c63834393a5f806e375b0816dc110c3be93d44
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR 'Remove query and fragment from doi.org links when parsing DOIs' also updates three submodule pointers (abbrv.jabref.org, csl-locales, csl-styles) that are unrelated to DOI parsing.
## Fix Focus Areas
- jablib/src/main/resources/csl-styles[1-1]
- jablib/src/main/resources/csl-locales[1-1]
- jablib/src/main/abbrv.jabref.org[1-1]
## Recommended Fix
Revert the three submodule pointer changes in this PR so it contains only the DOI and URLUtil changes, the test updates, and the changelog line. If the bumps are actually needed, land them in a separate PR with its own description and testing.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



View low (1)
Informational
5. Query stripping skips DOI links containing a line break 🐞 Bug
Description
URLUtil.removeQueryAndFragment uses the pattern [?#].*$, where . does not match line
terminators and $ only matches before a final terminator. A doi.org link with a line break inside
its query or fragment (for example pasted from a wrapped text block) therefore matches nothing and
the tracking parameters are kept, so the copied link stays broken. This only affects interior line
breaks, since doi.trim() already removes leading and trailing ones.
Code

jablib/src/main/java/org/jabref/logic/util/URLUtil.java[R27-29]

+    // Matches the query part ("?...") and/or the fragment part ("#...") at the end of a URL
+    private static final Pattern QUERY_AND_FRAGMENT = Pattern.compile("[?#].*$");
// Detect Google search URL
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
Issue description
The regex `[?#].*$` in URLUtil does not strip a query or fragment that contains an interior line terminator, because `.` does not cross line breaks and `$` only matches at the end of input.
Fix Focus Areas
- jablib/src/main/java/org/jabref/logic/util/URLUtil.java[27-40]
Recommended Fix
Change the pattern to `Pattern.compile("[?#].*\\z", Pattern.DOTALL)` or `Pattern.compile("(?s)[?#].*\\z")`, and add a unit test with a query containing `\n` in the middle of the string.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Resolved findings
1. Stray blank line churns untouched code ✓ Resolved
Description
DOI.java adds a single blank line between the EXACT_DOI_PATT and FIND_DOI_PATT constants, a
hunk with no functional change. The line splits a contiguous constant block and adds diff noise that
reviewers must check and that later readers may mistake for a meaningful edit.

2. Changelog entry links to a non-existent GitHub page ✓ Resolved
Description
The new CHANGELOG line links to https://github.com/JabRef/issues/17689, dropping the jabref path
segment, so readers who follow it land on a 404 instead of the fixed issue. The same sentence also
contains the typo proucing and an inserted space in the example parameter `'?
utm_source=newsletter'`, which misstates the actual URL text.

3. Method declaration has inconsistent brace spacing ✓ Resolved
Description
The new removeQueryAndFragment signature in URLUtil is written as ...(@NonNull String url){
without a space before the opening brace, unlike the surrounding code style. This is cosmetic and
does not change behaviour.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Nov 5, 2026
/// Call this before URL decoding, because an encoded `%3F` or `%23` is a valid part of a DOI.
private static String removeTrackingParameters(String doi) {
String trimmed = doi.trim();
if (DOI_RESOLVER_PREFIX.matcher(trimmed).find()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

doi.org/bfrhmx parses correctly, but doi.org/bfrhmx?utm_source=x returns empty. Could we handle the tracking parameter for this short DOI form too and add a regression test?

@doraem-on doraem-on left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you strip tracking parameters from https://doi.org:443/... links too and add a test for that case

@github-actions github-actions Bot removed the status: changes-required Pull requests that are not yet complete label Nov 5, 2026
@AnishKmSingh

Copy link
Copy Markdown
Contributor Author

@doraem-on Thanks For the Suggestion , its Done. https://doi.org:443/.. links are now also cleaned and so I added a test case for it in DOTest.java.

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Nov 5, 2026

@doraem-on doraem-on left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing the :443 case. I retested doi.org/bfrhmx?utm_source=x and it still fails, while doi.org/bfrhmx works. Could you handle that once

@github-actions github-actions Bot added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Nov 5, 2026
@pluto-han

Copy link
Copy Markdown
Collaborator

@doraem-on Thanks a lot for the testing and code review

@github-actions github-actions Bot removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 6, 2026
@AnishKmSingh

Copy link
Copy Markdown
Contributor Author

@doraem-on
Thanks! Fixed in a9db27b: doi.org/bfrhmx?utm_source=x now gives https://doi.org/10/bfrhmx. Added tests for the doi.org/, https://doi.org/ and www.doi.org/ variants

@github-actions github-actions Bot added the status: changes-required Pull requests that are not yet complete label Nov 6, 2026
@AnishKmSingh

Copy link
Copy Markdown
Contributor Author

The failing databaseTest is SynchronizationSimulatorTest, which tests shared database group sync and is unrelated to this change. It failed in different test methods on different runs (simulateLiveSubgroupAdditionPropagation earlier simulateLiveGroupEditPropagation now) so it looks flaky (timing based waitUntil with a 10s limit)

@github-actions github-actions Bot added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: changes-required Pull requests that are not yet complete labels Nov 7, 2026

@subhramit subhramit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

@subhramit
subhramit added this pull request to the merge queue Nov 9, 2026
@github-actions github-actions Bot added status: to-be-merged PRs which are accepted and should go into the merge-queue. and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@subhramit
subhramit merged commit be8eb38 into JabRef:main Nov 9, 2026
76 of 77 checks passed
@jabref-machine

Copy link
Copy Markdown
Collaborator

Created backport PR for black-forest:

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin port-17713-to-black-forest
git worktree add --checkout .worktree/port-17713-to-black-forest port-17713-to-black-forest
cd .worktree/port-17713-to-black-forest
git reset --hard HEAD^
git cherry-pick -x be8eb38efb1417758479f63926c4d05a7f207176

Siedlerchr added a commit that referenced this pull request Nov 9, 2026
* refs/heads/main:
  Chore(deps): Bump gradle-wrapper from 9.8.2 to 9.9.0 (#17753)
  New Crowdin updates (#17745)
  Remove task notification when a task fails (#17124)
  Store keyring secrets without extra encryption and migrate legacy values (#13687) (#17504)
  Mark Library as modified after merging changes from a backup file (#17632)
  Remove query and fragment from doi.org links when parsing DOIs (#17713)
  Document AI layering architecture example in developer documentation (#17737)
  Extract key binding dispatching from MainTable (#17564)
Siedlerchr added a commit to Ujjwals17/jabref that referenced this pull request Nov 9, 2026
* main: (26 commits)
  Diagnose stalled GUI tests and align dependency versions (JabRef#17763)
  Keep entry table still while a search match is in view (JabRef#16905)
  Add BibSonomy as a web search fetcher (JabRef#17611)
  Chore(deps): Bump com.konghq:unirest-modules-gson from 4.11.3 to 4.11.4 in /versions (JabRef#17761)
  Apply KeyBindingDispatcher to entry editor, linked files and frame (JabRef#17571)
  Chore(deps): Bump org.hisp.dhis:json-tree from 1.12.0 to 1.13.0 in /versions (JabRef#17759)
  Chore(deps): Bump com.dlsc.pdfviewfx:pdfviewfx from 3.6.0 to 3.6.1 in /versions (JabRef#17760)
  Chore(deps): Bump io.github.classgraph:classgraph from 6.0.1 to 6.0.2 in /versions (JabRef#17758)
  Chore(deps): Bump tools.jackson:jackson-bom from 3.2.4 to 3.3.0 in /versions (JabRef#17757)
  Chore(deps): Bump com.nimbusds:oauth2-oidc-sdk from 11.38.2 to 11.39 in /versions (JabRef#17756)
  Chore(deps): Bump tools.maran:svg-materialdesign from 1.0.0 to 1.0.1 in /versions (JabRef#17754)
  Chore(deps): Bump com.konghq:unirest-java-core from 4.11.3 to 4.11.4 in /versions (JabRef#17755)
  Chore(deps): Bump gradle-wrapper from 9.8.2 to 9.9.0 (JabRef#17753)
  New Crowdin updates (JabRef#17745)
  Remove task notification when a task fails (JabRef#17124)
  Store keyring secrets without extra encryption and migrate legacy values (JabRef#13687) (JabRef#17504)
  Mark Library as modified after merging changes from a backup file (JabRef#17632)
  Remove query and fragment from doi.org links when parsing DOIs (JabRef#17713)
  Document AI layering architecture example in developer documentation (JabRef#17737)
  Extract key binding dispatching from MainTable (JabRef#17564)
  ...

# Conflicts:
#	jabkit/src/test/java/org/jabref/toolkit/service/ExportServiceTest.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: bib(la)tex dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) good first issue An issue intended for project-newcomers. Varies in difficulty. size: small status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copy DOI URL breaks links that contain a tracking parameter

5 participants