Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

AN-8888: Normalize the uri before loading data in EpubServer #142

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -47,6 +51,7 @@
import org.readium.sdk.android.PackageResource;
import org.readium.sdk.android.util.ResourceInputStream;

import android.text.TextUtils;
import android.util.Log;

import com.koushikdutta.async.AsyncServer;
Expand Down Expand Up @@ -183,6 +188,24 @@ public void onRequest(AsyncHttpServerRequest request,
uri = iHttpPrefix == 0 ? uri.substring(httpPrefix.length()) : uri;
uri = uri.startsWith("/") ? uri.substring(1) : uri;

String newUri = null;

try {
URI normalizedUri = new URI(URLDecoder.decode(uri, "UTF-8"));

normalizedUri = normalizedUri.normalize();
newUri = normalizedUri.toString();
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "onRequest: " + e.toString());
} catch (URISyntaxException e) {
Log.e(TAG, "onRequest: " + e.toString());
}
if (!quiet) {
Log.d(TAG, "onRequest: uri = " + uri + ", newUri = " + newUri);
}
if (!TextUtils.isEmpty(newUri)) {
uri = newUri;
}
int indexOfQ = uri.indexOf('?');
if (indexOfQ >= 0) {
uri = uri.substring(0, indexOfQ);
Expand Down