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

XQuery Update ignores namespace binding conflict #1482

Closed
joewiz opened this issue Jul 17, 2017 · 8 comments · Fixed by #4545
Closed

XQuery Update ignores namespace binding conflict #1482

joewiz opened this issue Jul 17, 2017 · 8 comments · Fixed by #4545
Assignees
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Milestone

Comments

@joewiz
Copy link
Member

joewiz commented Jul 17, 2017

What is the problem

eXist's XQuery Update facility overlooks namespace binding conflicts when inserting attributes. For example, given a query whose prolog binds the namespace prefix myns to the URI http://www.foo.com, an update expression in that query to insert an attribute myns:baz="qux" into a document where myns is bound to a different namespace URI, like http://www.bar.com, succeeds, despite the conflicting namespace bindings on the prefix myns.

What did you expect

I expected an error to be raised — along the lines of what Saxon raises:

XUDY0023: An update action creates a namespace binding that conflicts with an existing namespace binding on the same target element

For more on this error, see https://www.w3.org/TR/xquery-update-30/#ERRXUDY0023. (While eXist's XQuery Update spec isn't aligned with the W3C spec, it seems reasonable that a namespace binding conflict should raise an error.)

Describe how to reproduce or add a test

xquery version "3.1";

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

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

declare namespace myns="http://www.foo.com";

declare variable $ut:test {
    <x xmlns:myns="http://www.bar.com">
        <z/>
    </x>
};

declare %test:setup function ut:setup() {
    xmldb:store("/db", "test.xml", $ut:test)
};

declare %test:teardown function ut:teardown() {
    xmldb:remove("/db/test.xml")
};

declare %test:assertError("XUDY0023") function ut:insert-namespaced-attribute() {
    update insert attribute myns:baz { "qux" } into doc("/db/test.xml")/x/z
};

The equivalent test in Saxon:

test.xml

<x xmlns:myns="http://www.bar.com">
    <z/>
</x>

test.xq

xquery version "3.1";

declare namespace myns="http://www.foo.com";

let $doc := doc("test.xml")
return 
    insert node attribute myns:baz { "qux" } into $doc/x/z

Running this test in oXygen 19.0 (build 2017062918), the result is:

System ID: /Users/joe/Downloads/update-test/test.xq
Severity: error
Description: XUDY0023: An update action creates a namespace binding that conflicts with an existing namespace binding on the same target element
Start location: 7:39

Context information

  • eXist-db version + Git Revision hash: 3.4.0-SNAPSHOT+201707142259 (af161fd)
  • Java version: 1.8.0_131
  • Operating system: macOS 10.12.5
  • 32 or 64 bit: 64 bit
  • Any custom changes in e.g. conf.xml: No
@joewiz joewiz added the bug issue confirmed as bug label Mar 5, 2018
@duncdrum
Copy link
Contributor

still happening in 4.2.1 and 5.0.0 RC

@adamretter adamretter added this to the eXist-4.2.2 milestone Jun 14, 2018
@adamretter adamretter self-assigned this Jun 14, 2018
@adamretter adamretter modified the milestones: eXist-4.2.2, eXist-4.3.1 Jul 7, 2018
@adamretter adamretter modified the milestones: eXist-4.3.1, eXist-4.3.2 Jul 24, 2018
@adamretter adamretter modified the milestones: eXist-4.3.2, eXist-4.4.1 Sep 21, 2018
@duncdrum duncdrum modified the milestones: eXist-4.4.1, eXist-4.5.1 Nov 30, 2018
@duncdrum
Copy link
Contributor

we should add these as pending tests

@joewiz joewiz modified the milestones: eXist-4.5.1, eXist-4.6.2 Apr 6, 2019
@joewiz joewiz modified the milestones: eXist-4.6.2, eXist 4.7.1 May 24, 2019
@joewiz
Copy link
Member Author

joewiz commented May 31, 2019

Agreed.

@adamretter adamretter modified the milestones: eXist-4.7.1, eXist-4.7.2 Aug 14, 2019
@joewiz joewiz modified the milestones: eXist-4.7.2, eXist-5.0.1 Sep 10, 2019
@joewiz
Copy link
Member Author

joewiz commented Sep 10, 2019

Test still fails in eXist 5.0.0.

@adamretter adamretter modified the milestones: eXist-5.0.1, eXist-5.1.1 Nov 19, 2019
@adamretter adamretter modified the milestones: eXist-5.1.1, eXist-5.1.2 Dec 6, 2019
@adamretter adamretter modified the milestones: eXist-5.1.2, eXist-5.2.1 Jan 23, 2020
@adamretter
Copy link
Contributor

@joewiz Hmmm... would I not expect to get the result:

<x xmlns:myns="http://www.bar.com">
    <z xmlns:myns="http://www.foo.com" myns:baz="qux"/> 
</x>

@joewiz
Copy link
Member Author

joewiz commented Mar 9, 2020

@adamretter Yes, that would certainly be a valid result. However, eXist 5.2.0 returns the following result:

<x xmlns:myns="http://www.bar.com">
    <z myns:baz="qux"/>
</x>

This is an incorrect result, since the @baz attribute is bound to the bar.com namespace URI instead of the foo.com namespace URI it was bound to in the update expression.

@line-o line-o added the xquery issue is related to xquery implementation label Apr 8, 2020
@line-o line-o modified the milestones: eXist-5.2.1, eXist-6.0.0 Jun 28, 2021
@adamretter adamretter modified the milestones: eXist-6.0.0, eXist-7.0.0 Feb 14, 2022
@line-o
Copy link
Member

line-o commented Jul 28, 2022

Is this considered a breaking change? As the milestone is set to v7.

@adamretter
Copy link
Contributor

See the semantics numbered list under the examples in the spec here - https://www.w3.org/TR/xquery-update-10/#id-insert
Especially item 3, which talks about an $alist:

  1. If $alist is not empty and any form of into is specified, the following checks are performed:

a. $target must be an element node [err:XUTY0022].

b. No attribute node in $alist may have a QName whose [implied namespace binding](https://www.w3.org/TR/xquery update-10/#dt-implied-namespace-binding) conflicts with a namespace binding in the "namespaces" property of $target [[err:XUDY0023](https://www.w3.org/TR/xquery-update 10/#ERRXUDY0023)], unless the namespace prefix for the attribute is absent.

c. Multiple attribute nodes in $alist must not have QNames whose implied namespace bindings conflict with each other [err:XUDY0024].

The definition of implied namespace bindings is here - https://www.w3.org/TR/xquery-update-10/#dt-implied-namespace-binding

[Definition: The implied namespace binding of a QName is the association of its namespace prefix (or absence thereof) with its namespace URI (or absence thereof).] [Definition: Two namespace bindings are said to conflict if their namespace prefixes (or absence thereof) are the same but their namespace URI's (or absence thereof) are different.]

alanpaxton added a commit to evolvedbinary/exist that referenced this issue Sep 6, 2022
@see eXist-db#1482

Report an error (XUDY0023) when an insertion is attempted with a node or attribute name in a namespace that conflicts with one which exists in the document.

Check node/attributes inserted recursively.
TBD - can subtrees of the inserted node be in different namespaces ? Do we need to deal with namespaces introduced in the insertion ?
alanpaxton added a commit to evolvedbinary/exist that referenced this issue Sep 7, 2022
@see eXist-db#1482

Report an error (XUDY0023) when an insertion is attempted with a node or attribute name in a namespace that conflicts with one which exists in the document.

@see https://www.w3.org/TR/xquery-update-30/#dt-conflict

Check node/attributes inserted recursively. This change does not look at namespaces introduced in the subtrees being inserted, so there is still potential for a conflict in the final tree.
We will consider rejecting conflicting namespaces introduced in the insertion in a later change.
alanpaxton added a commit to evolvedbinary/exist that referenced this issue Sep 7, 2022
@see eXist-db#1482

Report an error (XUDY0023) when an insertion is attempted with a node or attribute name in a namespace that conflicts with one which exists in the document.

@see https://www.w3.org/TR/xquery-update-30/#dt-conflict

Check node/attributes inserted recursively. This change does not look at namespaces introduced in the subtrees being inserted, so there is still potential for a conflict in the final tree.
We will consider rejecting conflicting namespaces introduced in the insertion in a later change.
alanpaxton added a commit to evolvedbinary/exist that referenced this issue Sep 8, 2022
@see eXist-db#1482

Report an error (XUDY0023) when an insertion is attempted with a node or attribute name in a namespace that conflicts with one which exists in the document.

@see https://www.w3.org/TR/xquery-update-30/#dt-conflict

Check node/attributes inserted recursively. This change does not look at namespaces introduced in the subtrees being inserted, so there is still potential for a conflict in the final tree.
We will consider rejecting conflicting namespaces introduced in the insertion in a later change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug xquery issue is related to xquery implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants