Skip to content

Commit

Permalink
Rewrote ClipboardUtils regex (#1361)
Browse files Browse the repository at this point in the history
Co-authored-by: cyian-1756 <[email protected]>
  • Loading branch information
cyian-1756 and cyian-1756 authored Jan 7, 2025
1 parent 4eaaabf commit 013da34
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/main/java/com/rarchives/ripme/ui/ClipboardUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,7 @@ public void run() {
// Check clipboard
String clipboard = ClipboardUtils.getClipboardString();
if (clipboard != null) {
Pattern p = Pattern.compile(
// TODO: This regex is a monster and doesn't match all links; It needs to be rewritten
"\\b(((ht|f)tp(s?)://|~/|/)|www.)" +
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
"|mil|biz|info|mobi|name|aero|jobs|museum" +
"|travel|cafe|[a-z]{2}))(:[\\d]{1,5})?" +
"(((/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?" +
"((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" +
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
Pattern p = Pattern.compile("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
Matcher m = p.matcher(clipboard);
while (m.find()) {
String url = m.group();
Expand Down

0 comments on commit 013da34

Please sign in to comment.