simpler support for single quotes (#681)

This commit is contained in:
Athou
2014-11-26 15:25:38 +01:00
parent 77c3ec0bbe
commit cca300e419
2 changed files with 4 additions and 4 deletions

View File

@@ -184,13 +184,13 @@ public class FeedUtils {
return null; return null;
} }
String pi = new String(ArrayUtils.subarray(bytes, 0, index + 1)); String pi = new String(ArrayUtils.subarray(bytes, 0, index + 1)).replace('\'', '"');
index = StringUtils.indexOf(pi, "encoding="); index = StringUtils.indexOf(pi, "encoding=\"");
if (index == -1) { if (index == -1) {
return null; return null;
} }
String encoding = pi.substring(index + 10, pi.length()); String encoding = pi.substring(index + 10, pi.length());
encoding = encoding.substring(0, Math.max(encoding.indexOf(' ') - 1, 0)); encoding = encoding.substring(0, encoding.indexOf('"'));
return encoding; return encoding;
} }

View File

@@ -60,6 +60,6 @@ public class FeedUtilsTest {
Assert.assertNull(FeedUtils.extractDeclaredEncoding("<feed></feed>".getBytes())); Assert.assertNull(FeedUtils.extractDeclaredEncoding("<feed></feed>".getBytes()));
Assert.assertEquals("UTF-8", FeedUtils.extractDeclaredEncoding("<?xml encoding=\"UTF-8\" ?>".getBytes())); Assert.assertEquals("UTF-8", FeedUtils.extractDeclaredEncoding("<?xml encoding=\"UTF-8\" ?>".getBytes()));
Assert.assertEquals("UTF-8", FeedUtils.extractDeclaredEncoding("<?xml encoding='UTF-8' ?>".getBytes())); Assert.assertEquals("UTF-8", FeedUtils.extractDeclaredEncoding("<?xml encoding='UTF-8' ?>".getBytes()));
Assert.assertEquals("UTF-8", FeedUtils.extractDeclaredEncoding("<?xml encoding='UTF-8'?>".getBytes()));
} }
} }