mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03: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.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -914,19 +916,15 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
|
|||
* @return LinkedHashMap<LanguageCode,Description>
|
||||
*/
|
||||
private LinkedHashMap<String,String> getDescriptions(String s) {
|
||||
// trim spaces next to "=" and "|"
|
||||
s = s.replace(" =", "=").replace(" |", "|").replace("= ","=").replace("| ","|");
|
||||
int descriptionIndex = s.indexOf("description=");
|
||||
if(descriptionIndex == -1){
|
||||
descriptionIndex = s.indexOf("Description=");
|
||||
final Pattern pattern = Pattern.compile("[dD]escription *=(.*?)\n *\\|", Pattern.DOTALL);
|
||||
final Matcher matcher = pattern.matcher(s);
|
||||
String description = null;
|
||||
if (matcher.find()) {
|
||||
description = matcher.group();
|
||||
}
|
||||
|
||||
if( descriptionIndex == -1 ){
|
||||
if(description == null){
|
||||
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<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -466,6 +466,25 @@ class MediaDetailFragmentUnitTests {
|
|||
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
|
||||
@Throws(Exception::class)
|
||||
fun testGetDescriptionList() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue