Skip to content

Commit

Permalink
Fix DeviceActivity#persistableAddresses to be more graceful (fixes #147)
Browse files Browse the repository at this point in the history
and accept the same address syntax as syncthing core web UI does.
  • Loading branch information
Catfriend1 committed Dec 21, 2018
1 parent 8c56575 commit 152f152
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,27 @@ private void updateDevice() {
}

private List<String> persistableAddresses(CharSequence userInput) {
return isEmpty(userInput)
? DYNAMIC_ADDRESS
: Arrays.asList(userInput.toString().split(" "));
if (isEmpty(userInput)) {
return DYNAMIC_ADDRESS;
}

/**
* Be fault-tolerant here.
* The user can write like this:
* tcp4://192.168.1.67:2222, dynamic
* tcp4://192.168.1.67:2222; dynamic
* tcp4://192.168.1.67:2222,dynamic
* tcp4://192.168.1.67:2222;dynamic
* tcp4://192.168.1.67:2222 dynamic
*/
String input = userInput.toString();
input = input.replace(",", " ");
input = input.replace(";", " ");
input = input.replaceAll("\\s+", ", ");
// Log.v(TAG, "persistableAddresses: Cleaned user input=" + input);

// Split and return the addresses as String[].
return Arrays.asList(input.split(", "));
}

private String displayableAddresses() {
Expand All @@ -542,7 +560,7 @@ private String displayableAddresses() {
List<String> list = DYNAMIC_ADDRESS.equals(mDevice.addresses)
? DYNAMIC_ADDRESS
: mDevice.addresses;
return TextUtils.join(" ", list);
return TextUtils.join(", ", list);
}

@Override
Expand Down

0 comments on commit 152f152

Please sign in to comment.