import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
-import java.net.URLEncoder;
import java.util.AbstractMap;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import java.util.Scanner;
protected URL getCanonicalUrl(URL source) {
if (isSearch(source)) {
// /post?tags=tag1+tag2 -> ../post/index/1/tag1%32tag2
- String key = "post?tags=";
+ String key = "?tags=";
if (source.toString().contains(key)) {
int pos = source.toString().indexOf(key);
String tags = source.toString().substring(pos + key.length());
- tags = tags.replace("+", "%32");
+ tags = tags.replace("+", "%20");
+
+ String base = source.toString().substring(0, pos);
+ if (!base.endsWith("/")) {
+ base += "/";
+ }
+ if (base.endsWith("/search/")) {
+ base = base.substring(0, base.indexOf("/search/") + 1);
+ }
+
try {
- return new URL(source.toString().substring(0, pos)
- + "post/index/1/" + tags);
+ return new URL(base + "index/1/" + tags);
} catch (MalformedURLException e) {
Instance.getTraceHandler().error(e);
}
}
}
+
return super.getCanonicalUrl(source);
}
private boolean isSearch(URL url) {
return url.getPath().startsWith("/post/index/")
- || (url.getPath().equals("/post") && url.getQuery().startsWith(
- "tags="));
+ || (url.getPath().equals("/post/search") && url.getQuery()
+ .startsWith("tags="));
}
}