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
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/freenet/clients/http/WelcomeToadlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ private void addCategoryToList(BookmarkCategory cat, HTMLNode list, boolean noAc
// 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.

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.

switch (keyType) {
case "USK":
case "SSK":
Matcher match = PATTERN_USK_SSK.matcher(key);
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.

if (match.matches()) {
Bombe marked this conversation as resolved.
Show resolved Hide resolved
key = match.group(1) + "activelink.png";
}
Expand All @@ -110,7 +111,7 @@ private void addCategoryToList(BookmarkCategory cat, HTMLNode list, boolean noAc
break;
case "CHK":
case "KSK": // This assumes the activelink is in the root of any one-shot directory upload.
Matcher match = PATTERN_BARE_SSK_CHK_KSK.matcher(key);
match = PATTERN_BARE_SSK_CHK_KSK.matcher(key);
if (match.matches()) {
key = match.group(1) + "activelink.png";
}
Expand Down