Skip to content

Commit

Permalink
Update fflogs URL parser
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Dec 11, 2024
1 parent c78dbea commit 7f15b68
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public record FflogsReportLocator(String report, @Nullable Integer fight) {

private static final Logger log = LoggerFactory.getLogger(FflogsReportLocator.class);
private static final Pattern urlPattern = Pattern.compile("reports/([^#/]+).*fight=(\\d+|last)");
private static final Pattern urlPattern = Pattern.compile("reports/([^#/?&]+).*fight=(\\d+|last)");
private static final Pattern urlPatternNoFight = Pattern.compile("reports/([^#/]+)");

public static FflogsReportLocator fromURL(String url) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gg.xp.xivsupport.events.fflogs;

import org.testng.Assert;
import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class FflogsReportLocatorTest {

@Test
void testNonFightUrl() {
FflogsReportLocator locator = FflogsReportLocator.fromURL("https://www.fflogs.com/reports/JX23Kd1YRyBtxkDZ");
Assert.assertEquals(locator.report(), "JX23Kd1YRyBtxkDZ");
Assert.assertNull(locator.fight());
Assert.assertFalse(locator.fightSpecified());
}

@Test
void testOldFightUrl() {
FflogsReportLocator locator = FflogsReportLocator.fromURL("https://www.fflogs.com/reports/JX23Kd1YRyBtxkDZ#fight=3");
Assert.assertEquals(locator.report(), "JX23Kd1YRyBtxkDZ");
Assert.assertEquals(locator.fight(), 3);
Assert.assertTrue(locator.fightSpecified());
}

@Test
void testNewFightUrl() {
FflogsReportLocator locator = FflogsReportLocator.fromURL("https://www.fflogs.com/reports/JX23Kd1YRyBtxkDZ?fight=3");
Assert.assertEquals(locator.report(), "JX23Kd1YRyBtxkDZ");
Assert.assertEquals(locator.fight(), 3);
Assert.assertTrue(locator.fightSpecified());
}

@Test
void testNewFightUrlWithJunk() {
FflogsReportLocator locator = FflogsReportLocator.fromURL("https://www.fflogs.com/reports/JX23Kd1YRyBtxkDZ?foo=bar&fight=3&baz=true");
Assert.assertEquals(locator.report(), "JX23Kd1YRyBtxkDZ");
Assert.assertEquals(locator.fight(), 3);
Assert.assertTrue(locator.fightSpecified());
}


}

0 comments on commit 7f15b68

Please sign in to comment.