Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include Mozilla public suffix list file directly #571

Closed
wants to merge 2 commits into from

Conversation

massdosage
Copy link
Contributor

As discussed on the dev mailing list, this should fix the failing TestPublicSuffixMatcher tests on Windows.

@garydgregory
Copy link
Member

Hello @massdosage

FWIW, Paths.get("mozilla", "public-suffix-list.txt").toString() would be better here but not really needed unless Paths where used in the test. The "/" does not matter in Java on or off Windows, Java normalizes the path for the platform.

The test set up is also problematic because it leaks a file handle. We should be using a try-with-resource here:

        // Create a matcher using a custom crafted public suffix list file
        try (InputStream in = classLoader.getResourceAsStream(SOURCE_FILE)) {
            Assertions.assertNotNull(in);
            final List<PublicSuffixList> lists = PublicSuffixListParser.INSTANCE.parseByType(new InputStreamReader(in, StandardCharsets.UTF_8));
            matcher = new PublicSuffixMatcher(lists);
        }

I fixed the above resource leak in git master.

The issue remains with the odd test failure on my end though :-(

@massdosage
Copy link
Contributor Author

OK, the SOURCE_FILE code was already there before any of my changes so I purposefully didn't touch it but the try-with-resources you suggest looks good. Even if this PR doesn't fix the issue at least it will give a better error messages if the mozilla file wasn't downloaded.

I'm happy to make any changes you suggest here though.

@@ -40,8 +42,7 @@
class TestPublicSuffixMatcher {

private static final String SOURCE_FILE = "suffixlistmatcher.txt";
private static final String PUBLIC_SUFFIX_LIST_FILE = "mozilla/public-suffix-list.txt";
Copy link
Member

Choose a reason for hiding this comment

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

@massdosage That notation should work on all platforms. I am quite sure of it. This is not the right fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, yeah, it's been ages since I touched Windows so I wasn't sure. In much earlier versions of Java this would have been an issue. If we instead prefer including the mozilla file in this repo like we do with SOURCE_FILE I can adjust this PR to do that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made that change here now.

@garydgregory
Copy link
Member

garydgregory commented Aug 23, 2024

Ah, this PR looks like a partial duplicate of #574 except that #574 preserves the ability to refresh the DAT file. Also this PR removes the download plugin from build section but it's still used from a profile.

@massdosage massdosage changed the title Use platform-agnostic file separator to fix test failing on Windows Include Mozilla public suffix list file directly Aug 23, 2024
@massdosage
Copy link
Contributor Author

Feel free to close this one and use #574 instead.

@ok2c ok2c closed this Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants