You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/07 22:42:55 UTC
svn commit: r1370510 -
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java
Author: prestonc
Date: Tue Aug 7 20:42:55 2012
New Revision: 1370510
URL: http://svn.apache.org/viewvc?rev=1370510&view=rev
Log:
Added an exception for non hex characters and odd length strings.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java?rev=1370510&r1=1370509&r2=1370510&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToHexBinaryOperation.java Tue Aug 7 20:42:55 2012
@@ -5,6 +5,7 @@ import java.io.IOException;
import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable;
import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
import org.apache.vxquery.runtime.functions.strings.ICharacterIterator;
import org.apache.vxquery.runtime.functions.strings.UTF8StringCharacterIterator;
@@ -34,8 +35,17 @@ public class CastToHexBinaryOperation ex
charIterator.reset();
abvsInner.reset();
int c1 = 0, c2 = 0;
- while ((c1 = charIterator.next()) != ICharacterIterator.EOS_CHAR
- && (c2 = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+ while ((c1 = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
+ c2 = charIterator.next();
+ if (c2 == ICharacterIterator.EOS_CHAR) {
+ // Odd number of characters.
+ throw new SystemException(ErrorCode.FORG0001);
+ }
+ if (Character.digit(c1, 16) < 0 || Character.digit(c1, 16) > 15 || Character.digit(c2, 16) < 0
+ || Character.digit(c2, 16) > 15) {
+ // Invalid of characters.
+ throw new SystemException(ErrorCode.FORG0001);
+ }
dOutInner.write(((Character.digit(c1, 16) << 4) + Character.digit(c2, 16)));
}