Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] castable as for untyped atomic value(s) #4900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public static AtomicValue convertTo(UntypedAtomicValue strVal, String value, int
return strVal == null ? new UntypedAtomicValue(expression, value) : strVal;
case Type.STRING:
return new StringValue(expression, value);
case Type.NORMALIZED_STRING:
case Type.TOKEN:
case Type.LANGUAGE:
case Type.NMTOKEN:
case Type.NAME:
case Type.NCNAME:
case Type.ID:
case Type.IDREF:
case Type.ENTITY:
return new StringValue(expression, value, requiredType);
case Type.ANY_URI:
return new AnyURIValue(expression, value);
case Type.BOOLEAN:
Expand Down
79 changes: 79 additions & 0 deletions exist-core/src/test/xquery/xquery3/castable-untyped-atomic.xqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

(:
: eXist-db Open Source Native XML Database
: Copyright (C) 2001 The eXist-db Authors
:
: [email protected]
: http://www.exist-db.org
:
: This library is free software; you can redistribute it and/or
: modify it under the terms of the GNU Lesser General Public
: License as published by the Free Software Foundation; either
: version 2.1 of the License, or (at your option) any later version.
:
: This library is distributed in the hope that it will be useful,
: but WITHOUT ANY WARRANTY; without even the implied warranty of
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
: Lesser General Public License for more details.
:
: You should have received a copy of the GNU Lesser General Public
: License along with this library; if not, write to the Free Software
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
:)
(:~
: @see https://github.com/eXist-db/exist/issues/4518
:)
xquery version "3.1";

module namespace ca="http://exist-db.org/xquery/test";

declare namespace test="http://exist-db.org/xquery/xqsuite";

(: atomic values not explicitly converted to strings were falsely returning false to _castable_as_
in other words, all these tests were returning nc="false"
:)
declare
%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>")
%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>")
%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>")
%test:args("123") %test:assertEquals("<result name=""123"" nc=""false""/>")
%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>")
%test:args("pfx:suffix") %test:assertEquals("<result name=""pfx:suffix"" nc=""false""/>")
function ca:n-castable($d) {
let $doc := <e name="e"><f n="{$d}"/></e>
let $el := $doc/descendant::*[exists(@n)]
let $n := $el/@n
return <result name="{$n}" nc="{$n castable as xs:NCName}"/>
};

(: explicit string conversion was always working - for reference :)
declare
%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>")
%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>")
%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>")
%test:args("123") %test:assertEquals("<result name=""123"" nc=""false""/>")
%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>")
%test:args("pfx:suffix") %test:assertEquals("<result name=""pfx:suffix"" nc=""false""/>")
function ca:s-castable($d) {
let $doc := <e name="e"><f n="{$d}"/></e>
let $el := $doc/descendant::*[exists(@n)]
let $n := $el/@n, $s := string($n)
return <result name="{$n}" nc="{$s castable as xs:NCName}"/>
};

(: sanity check that casting accepts the same values as castable as :)
declare
%test:args("ixml") %test:assertEquals("<result name=""ixml"" nc=""true""/>")
%test:args("comment") %test:assertEquals("<result name=""comment"" nc=""true""/>")
%test:args("apple-jack") %test:assertEquals("<result name=""apple-jack"" nc=""true""/>")
%test:args("123") %test:assertError("err:")
%test:args("élève") %test:assertEquals("<result name=""élève"" nc=""true""/>")
%test:args("pfx:suffix") %test:assertError("err:")
function ca:s-cast-castable($d) {
let $doc := <e name="e"><f n="{$d}"/></e>
let $el := $doc/descendant::*[exists(@n)]
let $n := $el/@n, $ncname := xs:NCName($n)
return <result name="{$n}" nc="{$ncname castable as xs:NCName}"/>
};


Loading