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

fix default bookmarks activelinks #873

Open
wants to merge 8 commits into
base: next
Choose a base branch
from

Conversation

TheSeeker
Copy link
Contributor

Bookmarks may not point to the root of a site, so use regex to construct the activelink instead of blindly tacking activelink.png at the end.

This assumes activelinks are always in the root.

@Bombe
Copy link
Contributor

Bombe commented Oct 22, 2023

Yeah, you’re not gonna sneak that one in without a test. 😄

Regex was too greedy, matched last instance of what looks like an edition isntead of the first.
@ArneBab
Copy link
Contributor

ArneBab commented Oct 27, 2023

Our build system seems unhappy about Capitalized Case.

@Bombe
Copy link
Contributor

Bombe commented Oct 27, 2023

Uh, yeah, as should have been @TheSeeker’s IDE?! Because that’s not valid Java…

fix Switch/Case -> switch/case
fix missing parens.
fix scope issue.
Copy link
Contributor

@Bombe Bombe left a comment

Choose a reason for hiding this comment

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

And the test is still missing! 🙂

@@ -91,10 +91,11 @@ private void addCategoryToList(BookmarkCategory cat, HTMLNode list, boolean noAc
// extract the key type
String keyType = initialKey.substring(1,3);
String key = '/' + initialKey + (initialKey.endsWith("/") ? "" : "/");
Matcher match = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing that match is not used anywhere outside the two branches within the switch statement, I believe “fix scope issue” and this change are diametrally opposed. 😀

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but the switch branches share the scope, so that’s how it has to be to avoid inventing new names for the different branches.

src/freenet/clients/http/WelcomeToadlet.java Show resolved Hide resolved
@@ -80,7 +88,42 @@ private void addCategoryToList(BookmarkCategory cat, HTMLNode list, boolean noAc
HTMLNode cell = row.addChild("td", "style", "border: none;");
if (item.hasAnActivelink() && !noActiveLinks) {
String initialKey = item.getKey();
String key = '/' + initialKey + (initialKey.endsWith("/") ? "" : "/") + "activelink.png";
// extract the key type
String keyType = initialKey.substring(1,3);
Copy link
Contributor

Choose a reason for hiding this comment

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

this has to go from 0 to 3 — Java is zero-indexed.

switch (keyType) {
case "USK":
case "SSK":
match = PATTERN_USK_SSK.matcher(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

this only matches when the key is already well-formed ⇒ ideally extract to a static method (uses no this; just put static before the function name to compiler-check that), and write a test that takes the existing bookmarks as input (and maybe some bad but valid examples) and returns the correct key for the activelink.

@ArneBab
Copy link
Contributor

ArneBab commented Jul 25, 2024

I agree very much that we need this fix (thank you!), but the current implementation is still buggy. A test just for the key adjustment should make this much easier to develop.

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