Skip to content

Commit

Permalink
Make property name validation optional
Browse files Browse the repository at this point in the history
Damn icloud.

Bump v0.9.10-fc
  • Loading branch information
blendmaster committed Jul 22, 2015
1 parent 903669f commit a6e1f87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 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.9-fc</version>
<version>0.9.10-fc</version>
<name>ez-vcard</name>
<url>http://code.google.com/p/ez-vcard</url>
<inceptionYear>2012</inceptionYear>
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/ezvcard/io/text/VCardRawWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class VCardRawWriter implements Closeable, Flushable {

private final FoldedLineWriter writer;
private boolean caretEncodingEnabled = false;
private boolean propertyValidationEnabled = true;
private ParameterValueChangedListener parameterValueChangedListener;
private VCardVersion version;

Expand Down Expand Up @@ -272,6 +273,23 @@ public void setParameterValueChangedListener(ParameterValueChangedListener liste
parameterValueChangedListener = listener;
}

/**
* Whether property names are checked in strict adherence with the spec.
*/
public boolean isPropertyValidationEnabled() {
return propertyValidationEnabled;
}

/**
* Sets whether property names are checked in strict adherence with the spec, defaults
* to on. Turning this off may be useful when dealing with regrettably lenient services,
* e.g. iCloud, which calls anything before the first colon and after the
* first period (group) as the property name.
*/
public void setPropertyValidationEnabled(boolean propertyValidationEnabled) {
this.propertyValidationEnabled = propertyValidationEnabled;
}

/**
* Writes a property marking the beginning of a component (in other words,
* writes a "BEGIN:NAME" property).
Expand Down Expand Up @@ -331,7 +349,7 @@ public void writeProperty(String group, String propertyName, VCardParameters par
}

//validate the property name
if (!propertyNameRegex.matcher(propertyName).matches()) {
if (propertyValidationEnabled && !propertyNameRegex.matcher(propertyName).matches()) {
throw new IllegalArgumentException("Property name contains invalid characters. Valid characters are letters, numbers, and hyphens: " + propertyName);
}

Expand Down

0 comments on commit a6e1f87

Please sign in to comment.