Merge branch 'master' of git@github.com:yacy/yacy_search_server.git

pull/8/head
Michael Peter Christen 10 years ago
commit f5f88272e4

@ -1007,6 +1007,11 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
return token; return token;
} }
/**
* Evaluates url search part and returns attribute '=' value pairs
*
* @return map key=attribue name, value=string after '='
*/
public Map<String, String> getAttributes() { public Map<String, String> getAttributes() {
Map<String, String > map = new LinkedHashMap<>(); Map<String, String > map = new LinkedHashMap<>();
if (this.searchpart == null) return map; if (this.searchpart == null) return map;
@ -1016,7 +1021,7 @@ public class MultiProtocolURL implements Serializable, Comparable<MultiProtocolU
if (p != -1) { if (p != -1) {
map.put(element.substring(0, p), element.substring(p + 1)); map.put(element.substring(0, p), element.substring(p + 1));
} else { } else {
map.put(element.substring(0, p), ""); if (!element.isEmpty()) map.put(element, "");
} }
} }
return map; return map;

@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeSet; import java.util.TreeSet;
import org.junit.Test; import org.junit.Test;
@ -158,7 +159,7 @@ public class MultiProtocolURLTest {
for (String[] testString : testStrings) { for (String[] testString : testStrings) {
// desired conversion result // desired conversion result
System.out.print("orig uri: " + testString[0]); System.out.print("toNormalform orig uri: " + testString[0]);
String shouldBe = testString[1]; String shouldBe = testString[1];
// conversion result // conversion result
String resultUrl = new MultiProtocolURL(testString[0]).toNormalform(true); String resultUrl = new MultiProtocolURL(testString[0]).toNormalform(true);
@ -167,6 +168,30 @@ public class MultiProtocolURLTest {
System.out.println(" -> " + resultUrl); System.out.println(" -> " + resultUrl);
} }
} }
/**
* Test of getAttribute method, of class MultiProtocolURL.
*/
@Test
public void testGetAttribute() throws Exception {
// some test url/uri with problems in the past
String[][] testStrings = new String[][]{
// teststring , expectedresult
new String[]{"http://yacy.net?&test", "test"}
};
for (String[] testString : testStrings) {
// desired conversion result
System.out.print("test getAttribute: " + testString[0]);
String shouldBe = testString[1];
MultiProtocolURL resultUrl = new MultiProtocolURL(testString[0]);
Map<String, String> attr = resultUrl.getAttributes();
assertEquals("", attr.get(shouldBe));
System.out.println(" -> " + resultUrl.toNormalform(false));
}
}
} }

Loading…
Cancel
Save