improve URL normalizing in "Add Repo" and also support content:// URLs
This adds some case normalization to both the scheme and the host. This was previously messing up TreeUri content:// URLs like this: content://com.android.externalstorage.documents/tree/1AFB-2402%3A/document/1AFB-2402%3Atesty.at.or.at%2Ffdroid%2Frepo Turning them into: content://com.android.externalstorage.documents/tree/1AFB-2402:/document/1AFB-2402:testy.at.or.at/fdroid/repo
This commit is contained in:
parent
06f42f864f
commit
c83c8301e6
@ -674,17 +674,24 @@ public class ManageReposActivity extends AppCompatActivity
|
|||||||
* Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed.
|
* Currently it normalizes the path so that "/./" are removed and "test/../" is collapsed.
|
||||||
* This is done using {@link URI#normalize()}. It also removes multiple consecutive forward
|
* This is done using {@link URI#normalize()}. It also removes multiple consecutive forward
|
||||||
* slashes in the path and replaces them with one. Finally, it removes trailing slashes.
|
* slashes in the path and replaces them with one. Finally, it removes trailing slashes.
|
||||||
|
* <p>
|
||||||
|
* {@code content://} URLs used for repos stored on removable storage get messed up by
|
||||||
|
* {@link URI}.
|
||||||
*/
|
*/
|
||||||
private String normalizeUrl(String urlString) throws URISyntaxException {
|
private String normalizeUrl(String urlString) throws URISyntaxException {
|
||||||
if (urlString == null) {
|
if (urlString == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
URI uri = new URI(urlString);
|
Uri uri = Uri.parse(urlString);
|
||||||
if (!uri.isAbsolute()) {
|
if (!uri.isAbsolute()) {
|
||||||
throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories");
|
throw new URISyntaxException(urlString, "Must provide an absolute URI for repositories");
|
||||||
}
|
}
|
||||||
|
if (!uri.isHierarchical()) {
|
||||||
uri = uri.normalize();
|
throw new URISyntaxException(urlString, "Must provide an hierarchical URI for repositories");
|
||||||
|
}
|
||||||
|
if ("content".equals(uri.getScheme())) {
|
||||||
|
return uri.toString();
|
||||||
|
}
|
||||||
String path = uri.getPath();
|
String path = uri.getPath();
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1.
|
path = path.replaceAll("//*/", "/"); // Collapse multiple forward slashes into 1.
|
||||||
@ -692,9 +699,13 @@ public class ManageReposActivity extends AppCompatActivity
|
|||||||
path = path.substring(0, path.length() - 1);
|
path = path.substring(0, path.length() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new URI(uri.getScheme().toLowerCase(Locale.ENGLISH),
|
||||||
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(),
|
uri.getUserInfo(),
|
||||||
path, uri.getQuery(), uri.getFragment()).toString();
|
uri.getHost().toLowerCase(Locale.ENGLISH),
|
||||||
|
uri.getPort(),
|
||||||
|
path,
|
||||||
|
uri.getQuery(),
|
||||||
|
uri.getFragment()).normalize().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user