Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Issue 1184 handle escaped semicolons and fix test

git-svn-id: http://zxing.googlecode.com/svn/trunk@2221 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information...
commit ee34f756d6e660cacd3d825bed4c40d82caa7b13 1 parent 0e781f7
srowen authored
View
46 core/src/com/google/zxing/client/result/VCardResultParser.java
@@ -41,7 +41,7 @@
private static final Pattern VCARD_ESCAPES = Pattern.compile("\\\\([,;\\\\])");
private static final Pattern EQUALS = Pattern.compile("=");
private static final Pattern SEMICOLON = Pattern.compile(";");
- private static final Pattern SEMICOLONS = Pattern.compile(";+");
+ private static final Pattern UNESCAPED_SEMICOLONS = Pattern.compile("(?<!\\\\);+");
@Override
public AddressBookParsedResult parse(Result result) {
@@ -53,32 +53,24 @@ public AddressBookParsedResult parse(Result result) {
if (!m.find() || m.start() != 0) {
return null;
}
- List<List<String>> names = matchVCardPrefixedField("FN", rawText, true);
+ List<List<String>> names = matchVCardPrefixedField("FN", rawText, true, false);
if (names == null) {
// If no display names found, look for regular name fields and format them
- names = matchVCardPrefixedField("N", rawText, true);
+ names = matchVCardPrefixedField("N", rawText, true, false);
formatNames(names);
}
- List<List<String>> phoneNumbers = matchVCardPrefixedField("TEL", rawText, true);
- List<List<String>> emails = matchVCardPrefixedField("EMAIL", rawText, true);
- List<String> note = matchSingleVCardPrefixedField("NOTE", rawText, false);
- List<List<String>> addresses = matchVCardPrefixedField("ADR", rawText, true);
- if (addresses != null) {
- for (List<String> list : addresses) {
- String adr = list.get(0);
- // Semicolon separators -- just make them a newline
- adr = SEMICOLONS.matcher(adr).replaceAll("\n").trim();
- list.set(0, adr);
- }
- }
- List<String> org = matchSingleVCardPrefixedField("ORG", rawText, true);
- List<String> birthday = matchSingleVCardPrefixedField("BDAY", rawText, true);
+ List<List<String>> phoneNumbers = matchVCardPrefixedField("TEL", rawText, true, false);
+ List<List<String>> emails = matchVCardPrefixedField("EMAIL", rawText, true, false);
+ List<String> note = matchSingleVCardPrefixedField("NOTE", rawText, false, false);
+ List<List<String>> addresses = matchVCardPrefixedField("ADR", rawText, true, true);
+ List<String> org = matchSingleVCardPrefixedField("ORG", rawText, true, false);
+ List<String> birthday = matchSingleVCardPrefixedField("BDAY", rawText, true, false);
if (birthday != null && !isLikeVCardDate(birthday.get(0))) {
birthday = null;
}
- List<String> title = matchSingleVCardPrefixedField("TITLE", rawText, true);
- List<String> url = matchSingleVCardPrefixedField("URL", rawText, true);
- List<String> instantMessenger = matchSingleVCardPrefixedField("IMPP", rawText, true);
+ List<String> title = matchSingleVCardPrefixedField("TITLE", rawText, true, false);
+ List<String> url = matchSingleVCardPrefixedField("URL", rawText, true, false);
+ List<String> instantMessenger = matchSingleVCardPrefixedField("IMPP", rawText, true, false);
return new AddressBookParsedResult(toPrimaryValues(names),
null,
toPrimaryValues(phoneNumbers),
@@ -97,7 +89,8 @@ public AddressBookParsedResult parse(Result result) {
private static List<List<String>> matchVCardPrefixedField(CharSequence prefix,
String rawText,
- boolean trim) {
+ boolean trim,
+ boolean parseFieldDivider) {
List<List<String>> matches = null;
int i = 0;
int max = rawText.length();
@@ -172,7 +165,13 @@ public AddressBookParsedResult parse(Result result) {
}
if (quotedPrintable) {
element = decodeQuotedPrintable(element, quotedPrintableCharset);
+ if (parseFieldDivider) {
+ element = UNESCAPED_SEMICOLONS.matcher(element).replaceAll("\n").trim();
+ }
} else {
+ if (parseFieldDivider) {
+ element = UNESCAPED_SEMICOLONS.matcher(element).replaceAll("\n").trim();
+ }
element = CR_LF_SPACE_TAB.matcher(element).replaceAll("");
element = NEWLINE_ESCAPE.matcher(element).replaceAll("\n");
element = VCARD_ESCAPES.matcher(element).replaceAll("$1");
@@ -253,8 +252,9 @@ private static void maybeAppendFragment(ByteArrayOutputStream fragmentBuffer,
static List<String> matchSingleVCardPrefixedField(CharSequence prefix,
String rawText,
- boolean trim) {
- List<List<String>> values = matchVCardPrefixedField(prefix, rawText, trim);
+ boolean trim,
+ boolean parseFieldDivider) {
+ List<List<String>> values = matchVCardPrefixedField(prefix, rawText, trim, parseFieldDivider);
return values == null || values.isEmpty() ? null : values.get(0);
}
View
2  core/src/com/google/zxing/client/result/VEventResultParser.java
@@ -74,7 +74,7 @@ public CalendarParsedResult parse(Result result) {
private static String matchSingleVCardPrefixedField(CharSequence prefix,
String rawText,
boolean trim) {
- List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, trim);
+ List<String> values = VCardResultParser.matchSingleVCardPrefixedField(prefix, rawText, trim, false);
return values == null || values.isEmpty() ? null : values.get(0);
}
View
2  core/test/src/com/google/zxing/client/result/AddressBookParsedResultTestCase.java
@@ -84,7 +84,7 @@ public void testQuotedPrintable() {
"=38=38=20=4C=79=6E=62=72=6F=6F=6B=0D=0A=43=\r\n" +
"=4F=20=36=39=39=\r\n" +
"=39=39;;;\r\nEND:VCARD",
- null, null, null, new String[] {";;88 Lynbrook\r\nCO 69999;;;"},
+ null, null, null, new String[] {"88 Lynbrook\r\nCO 69999"},
null, null, null, null, null, null);
}
Please sign in to comment.
Something went wrong with that request. Please try again.