mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
Issue 1054 unescape vCard / VEVENT correctly and don't strip semicolon in vCard
git-svn-id: https://zxing.googlecode.com/svn/trunk@2021 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
f328cb618e
commit
5311b1ce27
|
@ -37,6 +37,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
private static final Pattern BEGIN_VCARD = Pattern.compile("BEGIN:VCARD", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern VCARD_LIKE_DATE = Pattern.compile("\\d{4}-?\\d{2}-?\\d{2}");
|
||||
private static final Pattern CR_LF_SPACE_TAB = Pattern.compile("\r\n[ \t]");
|
||||
private static final Pattern NEWLINE_ESCAPE = Pattern.compile("\\\\[nN]");
|
||||
private static final Pattern VCARD_ESCAPES = Pattern.compile("\\\\([,;\\\\])");
|
||||
private static final Pattern EQUALS = Pattern.compile("=");
|
||||
private static final Pattern SEMICOLON = Pattern.compile(";");
|
||||
|
||||
|
@ -62,7 +64,7 @@ public final class VCardResultParser extends ResultParser {
|
|||
List<List<String>> addresses = matchVCardPrefixedField("ADR", rawText, true);
|
||||
if (addresses != null) {
|
||||
for (List<String> list : addresses) {
|
||||
list.set(0, formatAddress(list.get(0)));
|
||||
list.set(0, list.get(0));
|
||||
}
|
||||
}
|
||||
List<String> org = matchSingleVCardPrefixedField("ORG", rawText, true);
|
||||
|
@ -165,6 +167,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
element = decodeQuotedPrintable(element, quotedPrintableCharset);
|
||||
} else {
|
||||
element = CR_LF_SPACE_TAB.matcher(element).replaceAll("");
|
||||
element = NEWLINE_ESCAPE.matcher(element).replaceAll("\n");
|
||||
element = VCARD_ESCAPES.matcher(element).replaceAll("$1");
|
||||
}
|
||||
if (metadata == null) {
|
||||
List<String> match = new ArrayList<String>(1);
|
||||
|
@ -291,10 +295,6 @@ public final class VCardResultParser extends ResultParser {
|
|||
return value == null || VCARD_LIKE_DATE.matcher(value).matches();
|
||||
}
|
||||
|
||||
private static String formatAddress(String address) {
|
||||
return address == null ? null : address.replace(';', ' ').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats name fields of the form "Public;John;Q.;Reverend;III" into a form like
|
||||
* "Reverend John Q. Public III".
|
||||
|
|
|
@ -56,6 +56,12 @@ public final class AddressBookParsedResultTestCase extends Assert {
|
|||
null, new String[] {"Sean Owen"}, null, new String[] {"123 Main St"}, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEscapedVCard() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME:123\\;\\\\ Main\\, St\\nHome\r\nVERSION:2.1\r\nN:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, new String[] {"123;\\ Main, St\nHome"}, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBizcard() {
|
||||
doTest("BIZCARD:N:Sean;X:Owen;C:Google;A:123 Main St;M:+12125551212;E:srowen@example.org;",
|
||||
|
@ -75,10 +81,10 @@ public final class AddressBookParsedResultTestCase extends Assert {
|
|||
@Test
|
||||
public void testQuotedPrintable() {
|
||||
doTest("BEGIN:VCARD\r\nADR;HOME;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;;" +
|
||||
"=35=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
|
||||
"=38=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
|
||||
"=4F=20=36=39=39=\r\n" +
|
||||
"=32=36;;;\r\nEND:VCARD",
|
||||
null, null, null, new String[] {"58 Lynbrook\r\nCO 69926"},
|
||||
"=39=39;;;\r\nEND:VCARD",
|
||||
null, null, null, new String[] {";;88 Lynbrook\r\nCO 69999;;;"},
|
||||
null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,30 @@ public final class CalendarParsedResultTestCase extends Assert {
|
|||
null, null, null, "20080504T123456Z", "20080504T123456Z", null, -12.345, -45.678);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVEventEscapes() {
|
||||
doTest("BEGIN:VEVENT\n" +
|
||||
"CREATED:20111109T110351Z\n" +
|
||||
"LAST-MODIFIED:20111109T170034Z\n" +
|
||||
"DTSTAMP:20111109T170034Z\n" +
|
||||
"UID:0f6d14ef-6cb7-4484-9080-61447ccdf9c2\n" +
|
||||
"SUMMARY:Summary line\n" +
|
||||
"CATEGORIES:Private\n" +
|
||||
"DTSTART;TZID=Europe/Vienna:20111110T110000\n" +
|
||||
"DTEND;TZID=Europe/Vienna:20111110T120000\n" +
|
||||
"LOCATION:Location\\, with\\, escaped\\, commas\n" +
|
||||
"DESCRIPTION:Meeting with a friend\\nlook at homepage first\\n\\n\n" +
|
||||
" \\n\n" +
|
||||
"SEQUENCE:1\n" +
|
||||
"X-MOZ-GENERATION:1\n" +
|
||||
"END:VEVENT",
|
||||
"Meeting with a friend\nlook at homepage first\n\n\n \n",
|
||||
"Summary line",
|
||||
"Location, with, escaped, commas",
|
||||
"20111110T110000",
|
||||
"20111110T120000");
|
||||
}
|
||||
|
||||
private static void doTest(String contents,
|
||||
String description,
|
||||
String summary,
|
||||
|
|
Loading…
Reference in a new issue