Skip to content

Commit

Permalink
fixes #1638
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzzz authored and adamretter committed Jan 3, 2018
1 parent 60784b7 commit 9611363
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/org/exist/xquery/value/AbstractDateTimeValue.java
Expand Up @@ -359,9 +359,8 @@ public int compareTo(Collator collator, AtomicValue other) throws XPathException
}
return r;
}
throw new XPathException(
"Type error: cannot compare " + Type.getTypeName(getType()) + " to "
+ Type.getTypeName(other.getType()));
throw new XPathException(ErrorCodes.XPTY0004, "Type error: cannot compare " + Type.getTypeName(getType())
+ " to " + Type.getTypeName(other.getType()));
}

public AtomicValue max(Collator collator, AtomicValue other) throws XPathException {
Expand Down
23 changes: 17 additions & 6 deletions src/org/exist/xquery/value/AnyURIValue.java
Expand Up @@ -37,7 +37,7 @@
/**
* @author Wolfgang Meier (wolfgang@exist-db.org)
*/
public class AnyURIValue extends AtomicValue {
public class AnyURIValue extends AtomicValue {

public static final AnyURIValue EMPTY_URI = new AnyURIValue();
static final int caseDiff = ('a' - 'A');
Expand Down Expand Up @@ -288,13 +288,24 @@ public boolean compareTo(Collator collator, Comparison operator, AtomicValue oth
case LTEQ:
return cmp <= 0;
default:
throw new XPathException(
"XPTY0004: cannot apply operator "
+ operator.generalComparisonSymbol
+ " to xs:anyURI");
throw new XPathException(ErrorCodes.XPTY0004,
"cannot apply operator " + operator.generalComparisonSymbol + " to xs:anyURI");
}
} else {
return compareTo(collator, operator, other.convertTo(Type.ANY_URI));
AtomicValue atomicValue = null;

try {
atomicValue = other.convertTo(Type.ANY_URI);

} catch (XPathException ex) {

if (ex.getErrorCode() == ErrorCodes.FORG0001) {
throw new XPathException(ErrorCodes.XPTY0004, "cannot apply operator " + operator.generalComparisonSymbol + " to xs:anyURI");
}
throw ex;
}

return compareTo(collator, operator, atomicValue);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/exist/xquery/value/NumericValue.java
Expand Up @@ -3,6 +3,7 @@
import com.ibm.icu.text.Collator;
import org.exist.xquery.Constants;
import org.exist.xquery.Constants.Comparison;
import org.exist.xquery.ErrorCodes;
import org.exist.xquery.XPathException;

public abstract class NumericValue extends ComputableValue {
Expand Down Expand Up @@ -75,7 +76,7 @@ public boolean compareTo(Collator collator, Comparison operator, AtomicValue oth
throw new XPathException("Type error: cannot apply operator to numeric value");
}
}
throw new XPathException("Type error: cannot compare operands: " +
throw new XPathException(ErrorCodes.XPTY0004, "Type error: cannot compare operands: " +
Type.getTypeName(getType()) + " and " +
Type.getTypeName(other.getType()));
}
Expand Down
24 changes: 24 additions & 0 deletions test/src/xquery/namespaces.xql
Expand Up @@ -272,3 +272,27 @@ declare
function nt:qname-lhs-compare() {
xs:QName('test') eq 'test'
};

declare
%test:assertError("XPTY0004")
function nt:int-string-compare() {
5 eq 'five'
};

declare
%test:assertError("XPTY0004")
function nt:string-int-compare() {
'five' eq 5
};

declare
%test:assertError("XPTY0004")
function nt:uri-int-compare() {
xs:anyURI('5') eq 5
};

declare
%test:assertError("XPTY0004")
function nt:int-uri-compare() {
5 eq xs:anyURI('5')
};

0 comments on commit 9611363

Please sign in to comment.