AtomicWiki icon indicating copy to clipboard operation
AtomicWiki copied to clipboard

[BUG] Cardinality error on wiki/blogs/eXist/XQuery31

Open lguariento opened this issue 3 years ago • 5 comments

Hello,

the https://exist-db.org/exist/apps/wiki/blogs/eXist/XQuery31 link returns an error:

exerr:ERROR XPTY0004: The actual cardinality for parameter 1 does not match the cardinality declared in the function's signature: ($language as xs:string, $code as xs:string) item()*. Expected cardinality: exactly one, got 0. [at line 309, column 36, source: /db/apps/wiki/modules/atomic.xql]
In function:
	(xs:string, xs:string) [13:28:/db/apps/wiki/modules/atomic.xql]
	markdown:code(xs:string, map(*)) [450:34:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/markdown-0.7.1/content/markdown.xql]
	markdown:handle-block(xs:string, function(*)*, map(*)) [454:13:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/markdown-0.7.1/content/markdown.xql]
	markdown:handle-block(xs:string, function(*)*, map(*)) [461:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/markdown-0.7.1/content/markdown.xql]
	markdown:parse-blocks(xs:string*, map(*)) [138:30:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/markdown-0.7.1/content/markdown.xql]
	markdown:parse(xs:string?, map(*)+) [104:40:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/markdown-0.7.1/content/markdown.xql]
	atomic:get-content(element(atom:content)?, xs:boolean) [319:25:/db/apps/wiki/modules/atomic.xql]
	app:content(node(), map(*)) [-1:-1:/db/apps/wiki/modules/app.xql]
	templates:process-output(element(), map(*), item()*, element(function)) [211:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call-by-introspection(element(), map(*), map(*), function(*)) [189:28:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call(item(), element(), map(*)) [145:37:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [79:21:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	app:entries(node(), map(*), xs:string?, xs:string?, xs:string?, xs:int) [-1:-1:/db/apps/wiki/modules/app.xql]
	templates:process-output(element(), map(*), item()*, element(function)) [211:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call-by-introspection(element(), map(*), map(*), function(*)) [189:28:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call(item(), element(), map(*)) [145:37:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [237:13:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [148:81:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [428:17:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process-output(element(), map(*), item()*) [230:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process-output(element(), map(*), item()*, element(function)) [211:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call-by-introspection(element(), map(*), map(*), function(*)) [189:28:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:call(item(), element(), map(*)) [137:36:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [133:51:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:process(node()*, map(*)) [90:9:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]
	templates:apply(node()+, function(*), map(*)?, map(*)?) [31:5:/home/existdb/exist-db.org/exist-distribution-5.3.1/etc/../data/expathrepo/shared-0.9.1/content/templates.xql]

lguariento avatar Jan 29 '22 03:01 lguariento

Ok, I'm getting somewhere. It looks as though there is some issue with the markdown rendering of codeblocks. So, for the XQuery31 blog, for example, if we reduce it to:

<div class="row">
    <div class="col-md-6">
        The current development version of eXistdb includes full support for the array data type and related features from the [XQuery 3.1 Candidate Recommendation](http://www.w3.org/TR/xquery-31/#id-arrays). In combination with maps, arrays allow for a more "natural" representation of JSON in XQuery. Processing JSON or interfacing with external services returning JSON has become a lot more straightforward.
        
        But even if you are only mildly interested in JSON, arrays are a welcome addition to the XQuery language, mainly because unlike sequences, arrays can be nested. I guess most XQuery programmers have encountered a situation in which it would have been nice to return a sequence of sequences from a function. And sometimes you may want to indicate that particular items in a result sequence are empty. With arrays you can do all that. Arrays may contain other arrays or maps, sequences or even the empty sequence as members.
    </div>
    <div class="col-md-6">
        <figure>
        <iframe width="560" height="315" src="https://www.youtube.com/embed/XqehyfyjYWA" frameborder="0" allowfullscreen></iframe>
        <figcaption>Recorded presentation of this article during the eXistdb user pre-conference in Prague</figcaption>
        </figure>
    </div>
</div>

# Array Constructors

Array constructors come in two flavors: square and curly constructors. The square constructor will look familiar to most people:

'''xquery
let $array := [1, (), (3, 4)]
return
    $array(3)
'''

It all goes through. It takes only adding a carriage return after $array(3)''' to break everything.

I also tested on another problematic blog post (travisci) and I got the same behaviour. Up to the first codeblock everything works fine. As soon as I insert more content after the codeblock everything falls apart.

*I replaced ` with ' for display's sake.

lguariento avatar Jan 30 '22 20:01 lguariento

Also, it is clear that this is now related to this issue, so we should keep either one or the other.

lguariento avatar Jan 30 '22 20:01 lguariento

I have been able to further isolate the issue. I think it's in this line of code. If I hardcode the language to something like 'xquery' or 'yaml' then the rendering takes place (although all the code blocks are white, but hey).

I have reverted back to previous versions of markdown.xql and found out that up until this it was rendering something (although with unrendered blocks / HTML). This pull seems to have introduced the current issue.

lguariento avatar Jan 31 '22 00:01 lguariento

I think I solved it or at least found the core of the issue. Taking the $ (end of line) out makes the script do what we want.

I also tried with this, to no avail.

As far as I can see, this:

    if (matches($block, "^`{3,}.*\n.*?`{3,}", "ms")) then
        let $tokens := analyze-string($block, "^`{3,}(.*?)\n(.*)`{3,}", "ms")

does the job.

Screenshot 2022-01-31 at 01-35-51 Screenshot *From wiki/blogs/eXist/XQuery31

Shall I open a pull request?

lguariento avatar Jan 31 '22 01:01 lguariento

Sure, I can review your PR.

joewiz avatar Jan 31 '22 02:01 joewiz