Skip to content

Commit

Permalink
Don't process escape sequences in group names.
Browse files Browse the repository at this point in the history
Supercedes #3, since this
actually can work.
  • Loading branch information
AltSysrq committed Mar 9, 2016
1 parent b6a102c commit b47ea4a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<packaging>bundle</packaging> <!-- "bundle" used for OSGi support -->
<version>0.9.13-fc</version>
<version>0.9.14-fc</version>
<name>ez-vcard</name>
<url>http://github.com/fullcontact/ez-vcard</url>
<inceptionYear>2012</inceptionYear>
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/ezvcard/io/text/VCardRawLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import java.util.Arrays;

import lombok.ToString;

import ezvcard.parameter.VCardParameters;

/*
Copyright (c) 2012-2015, Michael Angstadt
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -29,14 +31,15 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/

/**
* Represents a parsed line from a vCard file.
* @author Michael Angstadt
*/
@ToString
public class VCardRawLine {
private final String group, name, value;
private final VCardParameters parameters;
Expand Down Expand Up @@ -160,4 +163,4 @@ public VCardRawLine build() {
return new VCardRawLine(group, name, parameters, value);
}
}
}
}
39 changes: 26 additions & 13 deletions src/main/java/ezvcard/io/text/VCardRawReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Expand All @@ -39,7 +39,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/

Expand All @@ -53,6 +53,7 @@
public class VCardRawReader implements Closeable {
private final Reader reader;
private final Buffer buffer = new Buffer();
private final Buffer unescapedBuffer = new Buffer();
private final Buffer unfoldedLine = new Buffer();

private boolean eos = false;
Expand Down Expand Up @@ -100,6 +101,7 @@ public VCardRawLine readLine() throws IOException {

propertyLineNum = lineNum;
buffer.clear();
unescapedBuffer.clear();
unfoldedLine.clear();

/*
Expand Down Expand Up @@ -183,6 +185,7 @@ public VCardRawLine readLine() throws IOException {
* line.
*/
buffer.chop();
unescapedBuffer.chop();
unfoldedLine.chop();
}

Expand Down Expand Up @@ -221,6 +224,7 @@ public VCardRawLine readLine() throws IOException {

if (inValue) {
buffer.append(ch);
unescapedBuffer.append(ch);
continue;
}

Expand Down Expand Up @@ -255,26 +259,32 @@ public VCardRawLine readLine() throws IOException {
buffer.append(escapeChar).append(ch);
}
}
unescapedBuffer.append(ch);
escapeChar = 0;
continue;
}

if (ch == '\\' || (ch == '^' && version != VCardVersion.V2_1 && caretDecodingEnabled)) {
//an escape character was read
escapeChar = ch;
unescapedBuffer.append(ch);
continue;
}

if (ch == '.' && group == null && propertyName == null) {
//set the group
group = buffer.getAndClear();
//Escape sequences are not to be processed
//in group names, so use unescapedBuffer.
group = unescapedBuffer.getAndClear();
buffer.clear();
continue;
}

if ((ch == ';' || ch == ':') && !inQuotes) {
if (propertyName == null) {
//property name
propertyName = buffer.getAndClear();
unescapedBuffer.clear();
} else {
//parameter value
String paramValue = buffer.getAndClear();
Expand All @@ -296,6 +306,7 @@ public VCardRawLine readLine() throws IOException {
if (ch == ',' && !inQuotes && version != VCardVersion.V2_1) {
//multi-valued parameter
parameters.put(curParamName, buffer.getAndClear());
unescapedBuffer.clear();
continue;
}

Expand All @@ -317,6 +328,7 @@ public VCardRawLine readLine() throws IOException {
}

buffer.append(ch);
unescapedBuffer.append(ch);
}

if (unfoldedLine.length() == 0) {
Expand All @@ -329,6 +341,7 @@ public VCardRawLine readLine() throws IOException {
}

String value = buffer.getAndClear();
unescapedBuffer.clear();

if ("VERSION".equalsIgnoreCase(propertyName)) {
VCardVersion version = VCardVersion.valueOfByStr(value);
Expand All @@ -347,7 +360,7 @@ public VCardRawLine readLine() throws IOException {
* accent encoding (enabled by default). This escaping mechanism allows
* newlines and double quotes to be included in parameter values.
* </p>
*
*
* <table class="simpleTable">
* <tr>
* <th>Raw Character</th>
Expand All @@ -366,16 +379,16 @@ public VCardRawLine readLine() throws IOException {
* <td>{@code ^^}</td>
* </tr>
* </table>
*
*
* <p>
* Example:
* </p>
*
*
* <pre>
* GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
* sburgh, PA 15212":40.446816;80.00566
* </pre>
*
*
* @return true if circumflex accent decoding is enabled, false if not
* @see <a href="http://tools.ietf.org/html/rfc6868">RFC 6868</a>
*/
Expand All @@ -389,7 +402,7 @@ public boolean isCaretDecodingEnabled() {
* accent encoding (enabled by default). This escaping mechanism allows
* newlines and double quotes to be included in parameter values.
* </p>
*
*
* <table class="simpleTable">
* <tr>
* <th>Raw Character</th>
Expand All @@ -408,16 +421,16 @@ public boolean isCaretDecodingEnabled() {
* <td>{@code ^^}</td>
* </tr>
* </table>
*
*
* <p>
* Example:
* </p>
*
*
* <pre>
* GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
* sburgh, PA 15212":geo:40.446816,-80.00566
* </pre>
*
*
* @param enable true to use circumflex accent decoding, false not to
* @see <a href="http://tools.ietf.org/html/rfc6868">RFC 6868</a>
*/
Expand Down
Loading

0 comments on commit b47ea4a

Please sign in to comment.