Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e9ce3e
Added Integrity message to identify whether the user inputs a full UR…
Jan 29, 2025
70199bf
Added tests to check whether a full URL is identified with an error i…
Jan 30, 2025
f445361
Fixed missing localisation keys in JabRef_en.properties
Jan 30, 2025
27d507e
removed added keys in JabRef_en.properties
Jan 30, 2025
e508a59
Add localization key
11raphael Jan 30, 2025
69f9af7
Fix book title checker URL pattern localization
11raphael Jan 30, 2025
febe100
amended and simplified integrity message for booktitle and title
Jan 30, 2025
a92651f
amended JabRef_en.properties file
Jan 30, 2025
00bc4e8
Adjusted Title
Jan 30, 2025
8e0e571
amended booktitle message and keys in JabRef_en.properties
Jan 30, 2025
4bf336d
removed DOMAIN_ONLY_PATTERN check as functionality was unaffected by …
Jan 31, 2025
41ba56a
Added an entry in CHANGELOG.md to specify that we have added an error…
Jan 31, 2025
6febffb
Amended an entry in CHANGELOG.md to specify that we have added an err…
Jan 31, 2025
553fb6e
resolved merge conflict
Jan 31, 2025
89f9bdb
Merge branch 'main' into fix-12354-title-should-not-contain-url
RapidShotzz Jan 31, 2025
f1c469a
refactored code to include Regex in URLUtil and adjusted testing.
Feb 6, 2025
b79fae5
Add title and booktitle tests for protocol without URL
11raphael Feb 6, 2025
4f8eb59
Remove unused FULL_URL_PATTERN and document URL_PATTERN
11raphael Feb 12, 2025
9c776c5
Update BooktitleChecker and Titlechecker
11raphael Feb 13, 2025
6cdd6d2
Add NoURLChecker
11raphael Feb 18, 2025
cddcade
Merge branch 'main' into fix-12354-title-should-not-contain-url
Siedlerchr Feb 18, 2025
6dd7484
Merge branch 'main' into fix-12354-title-should-not-contain-url
koppor Feb 25, 2025
ac0a98a
Fix JabRef_en.properties
koppor Feb 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We added a new CLI that supports txt, csv, and console-based output for consistency in BibTeX entries. [#11984](https://github.com/JabRef/jabref/issues/11984)
- We added a new dialog for bibliography consistency check. [#11950](https://github.com/JabRef/jabref/issues/11950)
- We added a feature for copying entries to libraries, available via the context menu, with an option to include cross-references. [#12374](https://github.com/JabRef/jabref/pull/12374)
- We added an integrity check if a URL appears in a title. [#12354](https://github.com/JabRef/jabref/issues/12354)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jabref/logic/integrity/FieldCheckers.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ private static Multimap<Field, ValueChecker> getAllMap(BibDatabaseContext databa
fieldCheckers.put(StandardField.KEY, new ValidCitationKeyChecker());
fieldCheckers.put(InternalField.KEY_FIELD, new ValidCitationKeyChecker());

fieldCheckers.put(StandardField.TITLE, new NoURLChecker());
fieldCheckers.put(StandardField.BOOKTITLE, new NoURLChecker());

if (databaseContext.isBiblatexMode()) {
fieldCheckers.put(StandardField.DATE, new DateChecker());
fieldCheckers.put(StandardField.URLDATE, new DateChecker());
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/jabref/logic/integrity/NoURLChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.URLUtil;
import org.jabref.model.strings.StringUtil;

public class NoURLChecker implements ValueChecker {

public Optional<String> checkValue(String value) {
if (StringUtil.isBlank(value)) {
return Optional.empty();
}

if (URLUtil.URL_PATTERN.matcher(value).find()) {
return Optional.of(Localization.lang("contains a URL"));
}

return Optional.empty();
}
}
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/logic/util/URLUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.regex.Pattern;

/**
* URL utilities for URLs in the JabRef logic.
* <p>
* For GUI-oriented URL utilities see {@link org.jabref.gui.fieldeditors.URLUtil}.
*/
public class URLUtil {

private static final String URL_REGEX = "(?i)\\b((?:https?|ftp)://[^\\s]+)";

/**
* Pattern matches a string containing a URL with a protocol
*/
public static final Pattern URL_PATTERN = Pattern.compile(URL_REGEX, Pattern.CASE_INSENSITIVE);

private static final String URL_EXP = "^(https?|ftp)://.+";
// Detect Google search URL
private static final String GOOGLE_SEARCH_EXP = "^https?://(?:www\\.)?google\\.[\\.a-z]+?/url.*";
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1626,16 +1626,18 @@ JabRef\ would\ not\ have\ been\ possible\ without\ the\ help\ of\ our\ contribut

HTML\ encoded\ character\ found=HTML encoded character found
booktitle\ ends\ with\ 'conference\ on'=booktitle ends with 'conference on'
contains\ a\ URL=contains a URL

incorrect\ control\ digit=incorrect control digit
incorrect\ format=incorrect format

Copied\ version\ to\ clipboard=Copied version to clipboard

Citation\ key=Citation key
Message=Message


MathSciNet\ Review=MathSciNet Review

Reset\ all=Reset all

Decryption\ not\ supported.=Decryption not supported.
Expand Down Expand Up @@ -2854,6 +2856,7 @@ Include=Include
Exclude=Exclude
Include\ or\ exclude\ cross-referenced\ entries=Include or exclude cross-referenced entries
Would\ you\ like\ to\ include\ cross-reference\ entries\ in\ the\ current\ operation?=Would you like to include cross-reference entries in the current operation?

Entries\ copied\ successfully,\ including\ cross-references.=Entries copied successfully, including cross-references.
Entries\ copied\ successfully,\ without\ cross-references.=Entries copied successfully, without cross-references.

Expand Down
30 changes: 30 additions & 0 deletions src/test/java/org/jabref/logic/integrity/NoURLCheckerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jabref.logic.integrity;

import java.util.Optional;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

public class NoURLCheckerTest {

private final NoURLChecker checker = new NoURLChecker();

@ParameterizedTest(name = "{index}. Title: \"{0}\"")
@CsvSource({
"Proceedings of the https://example.com/conference",
"Find more at http://mywebsite.org/article",
"Visit ftp://files.example.com/download",
})
void fieldShouldRaiseWarningForFullURLs(String title) {
assertNotEquals(Optional.empty(), checker.checkValue(title));
}

@Test
void fieldShouldAcceptURLWithoutProtocol() {
assertEquals(Optional.empty(), checker.checkValue("Applying Trip@dvice Recommendation Technology to www.visiteurope.com"));
}
}