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

xml serialization doesn't escape & #131

Closed
justin2004 opened this issue Dec 18, 2023 · 6 comments
Closed

xml serialization doesn't escape & #131

justin2004 opened this issue Dec 18, 2023 · 6 comments
Assignees
Labels
Milestone

Comments

@justin2004
Copy link

justin2004 commented Dec 18, 2023

$ cat query2.rq 
PREFIX wds: <http://www.wikidata.org/entity/statement/>
select * 
where {
  # wds:Q23-21309B07-59CA-4703-A191-D8CD4E7B3FBF ?p ?o .
wds:Q183-a03c757b-464a-b91f-f37f-b2207b057a66 ?p ?o .
}
$ curl -u USER:PASSWORD -X PUT "http://localhost:8080/basil" -H "X-Basil-Endpoint: https://query.wikidata.org/sparql" -T query2.rq

then hitting http://localhost:8080/basil/r1cvkhc78hfd/api in a browser:

This page contains the following errors:
error on line 18 at column 13: EntityRef: expecting ';'
Below is a rendering of the page up to the first error.
p o http://wikiba.se/ontology#rank http://wikiba.se/ontology#NormalRank http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://wikiba.se/ontology#BestRank http://www.wikidata.org/prop/statement/P8988

because there is a & in the bindings that doesn't get escaped when serializing as xml so the xml isn't well-formed.

@enridaga
Copy link
Contributor

Can you please paste the full source code of the response (including HTTP response headers)?

@justin2004
Copy link
Author

sure.

$ curl -v -H 'Accept: application/xml' 'http://localhost:8080/basil/r1cvkhc78hfd/api' > out.xml
*   Trying 127.0.0.1:8080...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /basil/r1cvkhc78hfd/api HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: application/xml
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 18 Dec 2023 19:55:36 GMT
< X-Basil-Api: http://localhost:8080/basil/r1cvkhc78hfd/api
< X-Basil-Alias: http://localhost:8080/basil/r1cvkhc78hfd/alias
< X-Basil-Spec: http://localhost:8080/basil/r1cvkhc78hfd/spec
< X-Basil-Direct: http://localhost:8080/basil/r1cvkhc78hfd/direct
< X-Basil-View: http://localhost:8080/basil/r1cvkhc78hfd/view
< X-Basil-Docs: http://localhost:8080/basil/r1cvkhc78hfd/docs
< X-Basil-Swagger: http://localhost:8080/basil/r1cvkhc78hfd/api-docs
< X-Basil-Creator: penelope
< Content-Type: application/xml; charset=UTF-8
< Content-Length: 461
< Server: Jetty(9.4.51.v20230217)
< 
{ [461 bytes data]
100   461  100   461    0     0   2646      0 --:--:-- --:--:-- --:--:--  2664
* Connection #0 to host localhost left intact
$ xmllint out.xml 
out.xml:18: parser error : EntityRef: expecting ';'
                        <o>osm&id=276</o>
                                 ^

@justin2004
Copy link
Author

justin2004 commented Dec 18, 2023

instead of building the xml sparql bindings like this

i wonder if we could jena's xml sparql bindings serialization code? not by copying it but by invoking it, i mean. jena directly can handle this situation:

curl --silent 'http://localhost:3000/sparql.anything'  \
--header "Accept: application/xml" \
--data-urlencode 'query=
select * 
WHERE {
bind("100 & 200" as ?what)
}'

yields:

<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="what"/>
  </head>
  <results>
    <result> 
      <binding name="what">
        <literal>100 &amp; 200</literal>
      </binding> 
    </result>
  </results>
</sparql>

notice the &amp; escape

@enridaga
Copy link
Contributor

Indeed, I can't remember the reason why that was implemented this way...

@enridaga
Copy link
Contributor

I added a fix in 99b4fff let me know if this solves your problem.

@enridaga enridaga self-assigned this Dec 19, 2023
@enridaga enridaga added the bug label Dec 19, 2023
@enridaga enridaga added this to the v0.8.4 milestone Dec 19, 2023
@justin2004
Copy link
Author

works now. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants