mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Issue 863: add limited support for VALUE=uri in vCard
This commit is contained in:
parent
649a099c68
commit
4ddc8c9e49
|
@ -20,6 +20,7 @@ import com.google.zxing.Result;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -125,6 +126,7 @@ public final class VCardResultParser extends ResultParser {
|
|||
List<String> metadata = null;
|
||||
boolean quotedPrintable = false;
|
||||
String quotedPrintableCharset = null;
|
||||
String valueType = null;
|
||||
if (metadataString != null) {
|
||||
for (String metadatum : SEMICOLON.split(metadataString)) {
|
||||
if (metadata == null) {
|
||||
|
@ -139,6 +141,8 @@ public final class VCardResultParser extends ResultParser {
|
|||
quotedPrintable = true;
|
||||
} else if ("CHARSET".equalsIgnoreCase(key)) {
|
||||
quotedPrintableCharset = value;
|
||||
} else if ("VALUE".equalsIgnoreCase(key)) {
|
||||
valueType = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +192,12 @@ public final class VCardResultParser extends ResultParser {
|
|||
element = NEWLINE_ESCAPE.matcher(element).replaceAll("\n");
|
||||
element = VCARD_ESCAPES.matcher(element).replaceAll("$1");
|
||||
}
|
||||
// Only handle VALUE=uri specially
|
||||
if ("uri".equals(valueType)) {
|
||||
// Don't actually support dereferencing URIs, but use scheme-specific part not URI
|
||||
// as value, to support tel: and mailto:
|
||||
element = URI.create(element).getSchemeSpecificPart();
|
||||
}
|
||||
if (metadata == null) {
|
||||
List<String> match = new ArrayList<>(1);
|
||||
match.add(element);
|
||||
|
|
|
@ -116,6 +116,16 @@ public final class AddressBookParsedResultTestCase extends Assert {
|
|||
null, null, null, null, null, null, null, null, null, null, "foo,bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardValueURI() {
|
||||
doTest("BEGIN:VCARD\r\nTEL;VALUE=uri:tel:+1-555-555-1212\r\nEND:VCARD",
|
||||
null, null, null, null, null, new String[] { "+1-555-555-1212" }, new String[] { null },
|
||||
null, null, null, null);
|
||||
|
||||
doTest("BEGIN:VCARD\r\nN;VALUE=text:Owen;Sean\r\nEND:VCARD",
|
||||
null, new String[] {"Sean Owen"}, null, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVCardTypes() {
|
||||
doTest("BEGIN:VCARD\r\nTEL;HOME:\r\nTEL;WORK:10\r\nTEL:20\r\nTEL;CELL:30\r\nEND:VCARD",
|
||||
|
|
Loading…
Reference in a new issue