-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a wrapper around URIs to fix issues with spaces
- Loading branch information
Showing
14 changed files
with
168 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 3 additions & 6 deletions
9
src/main/java/link/infra/packwiz/installer/metadata/PackFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/link/infra/packwiz/installer/metadata/SpaceSafeURI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package link.infra.packwiz.installer.metadata; | ||
|
||
import com.google.gson.annotations.JsonAdapter; | ||
|
||
import java.io.Serializable; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
|
||
// The world's worst URI wrapper | ||
@JsonAdapter(SpaceSafeURIParser.class) | ||
public class SpaceSafeURI implements Comparable<SpaceSafeURI>, Serializable { | ||
private final URI u; | ||
|
||
public SpaceSafeURI(String str) throws URISyntaxException { | ||
u = new URI(str.replace(" ", "%20")); | ||
} | ||
|
||
public SpaceSafeURI(URI uri) { | ||
this.u = uri; | ||
} | ||
|
||
public SpaceSafeURI(String scheme, String authority, String path, String query, String fragment) throws URISyntaxException { | ||
// TODO: do all components need to be replaced? | ||
scheme = scheme.replace(" ", "%20"); | ||
authority = authority.replace(" ", "%20"); | ||
path = path.replace(" ", "%20"); | ||
query = query.replace(" ", "%20"); | ||
fragment = fragment.replace(" ", "%20"); | ||
u = new URI(scheme, authority, path, query, fragment); | ||
} | ||
|
||
public String getPath() { | ||
return u.getPath().replace("%20", " "); | ||
} | ||
|
||
public String toString() { | ||
return u.toString().replace("%20", " "); | ||
} | ||
|
||
@SuppressWarnings("WeakerAccess") | ||
public SpaceSafeURI resolve(String path) { | ||
return new SpaceSafeURI(u.resolve(path.replace(" ", "%20"))); | ||
} | ||
|
||
public SpaceSafeURI resolve(SpaceSafeURI loc) { | ||
return new SpaceSafeURI(u.resolve(loc.u)); | ||
} | ||
|
||
public SpaceSafeURI relativize(SpaceSafeURI loc) { | ||
return new SpaceSafeURI(u.relativize(loc.u)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof SpaceSafeURI) { | ||
return u.equals(((SpaceSafeURI) obj).u); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int compareTo(SpaceSafeURI uri) { | ||
return u.compareTo(uri.u); | ||
} | ||
|
||
public String getScheme() { | ||
return u.getScheme(); | ||
} | ||
|
||
public String getAuthority() { | ||
return u.getAuthority(); | ||
} | ||
|
||
public String getHost() { | ||
return u.getHost(); | ||
} | ||
|
||
public URL toURL() throws MalformedURLException { | ||
return u.toURL(); | ||
} | ||
} |
Oops, something went wrong.