diff --git a/xivsupport/src/main/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocator.java b/xivsupport/src/main/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocator.java index 3791303e075a..94b3421454d6 100644 --- a/xivsupport/src/main/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocator.java +++ b/xivsupport/src/main/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocator.java @@ -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) { diff --git a/xivsupport/src/test/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocatorTest.java b/xivsupport/src/test/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocatorTest.java new file mode 100644 index 000000000000..03d2401a3b90 --- /dev/null +++ b/xivsupport/src/test/java/gg/xp/xivsupport/events/fflogs/FflogsReportLocatorTest.java @@ -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()); + } + + +} \ No newline at end of file