mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
parent
ffbfdabb3a
commit
c5b527f450
2 changed files with 27 additions and 10 deletions
|
|
@ -94,6 +94,8 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
@ -914,19 +916,15 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
||||||
* @return LinkedHashMap<LanguageCode,Description>
|
* @return LinkedHashMap<LanguageCode,Description>
|
||||||
*/
|
*/
|
||||||
private LinkedHashMap<String,String> getDescriptions(String s) {
|
private LinkedHashMap<String,String> getDescriptions(String s) {
|
||||||
// trim spaces next to "=" and "|"
|
final Pattern pattern = Pattern.compile("[dD]escription *=(.*?)\n *\\|", Pattern.DOTALL);
|
||||||
s = s.replace(" =", "=").replace(" |", "|").replace("= ","=").replace("| ","|");
|
final Matcher matcher = pattern.matcher(s);
|
||||||
int descriptionIndex = s.indexOf("description=");
|
String description = null;
|
||||||
if(descriptionIndex == -1){
|
if (matcher.find()) {
|
||||||
descriptionIndex = s.indexOf("Description=");
|
description = matcher.group();
|
||||||
}
|
}
|
||||||
|
if(description == null){
|
||||||
if( descriptionIndex == -1 ){
|
|
||||||
return new LinkedHashMap<>();
|
return new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
final String descriptionToEnd = s.substring(descriptionIndex+12);
|
|
||||||
final int descriptionEndIndex = descriptionToEnd.indexOf("\n|");
|
|
||||||
final String description = s.substring(descriptionIndex+12, descriptionIndex+12+descriptionEndIndex);
|
|
||||||
|
|
||||||
final LinkedHashMap<String,String> descriptionList = new LinkedHashMap<>();
|
final LinkedHashMap<String,String> descriptionList = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -466,6 +466,25 @@ class MediaDetailFragmentUnitTests {
|
||||||
Assert.assertEquals(map, method.invoke(fragment, s))
|
Assert.assertEquals(map, method.invoke(fragment, s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetDescriptionsWithLongSpaces() {
|
||||||
|
`when`(media.filename).thenReturn("")
|
||||||
|
val method: Method = MediaDetailFragment::class.java.getDeclaredMethod("getDescriptions", String::class.java)
|
||||||
|
method.isAccessible = true
|
||||||
|
val s = "=={{int:filedesc}}==\n" +
|
||||||
|
"{{Information\n" +
|
||||||
|
"|Description ={{en|1=The interior of Sacred Heart RC Church, Wimbledon, London.}}\n" +
|
||||||
|
"|Source ={{own}}\n" +
|
||||||
|
"|Author =[[User:Diliff|Diliff]]\n" +
|
||||||
|
"|Date =2015-02-17\n" +
|
||||||
|
"|Permission ={{Diliff/Licensing}}\n" +
|
||||||
|
"|other_versions=\n" +
|
||||||
|
"}}"
|
||||||
|
val map = linkedMapOf("en" to "The interior of Sacred Heart RC Church, Wimbledon, London.")
|
||||||
|
Assert.assertEquals(map, method.invoke(fragment, s))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testGetDescriptionList() {
|
fun testGetDescriptionList() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue