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

rdf2dot ampersand escape #1208

Closed
blake-regalia opened this issue Dec 4, 2020 · 3 comments · Fixed by #1209
Closed

rdf2dot ampersand escape #1208

blake-regalia opened this issue Dec 4, 2020 · 3 comments · Fixed by #1209

Comments

@blake-regalia
Copy link

rdf2dot is not escaping html characters in places it should. Here is minimum reproducible example:

from rdflib import URIRef, Literal
from rdflib.namespace import DC
subj = URIRef('eg://org/?foo=bar&baz=bux')
pred = URIRef('eg://org/predicate')
obj = URIRef('eg://org/object')

g = rdflib.Graph()
g.add((subj, pred, obj))
g.add((subj, DC.title, Literal('This & That')))
out = io.StringIO()
rdf2dot(g, out, opts={display})
out.getvalue()

outputs:

digraph { 
 node [ fontname="DejaVu Sans" ] ; 
	node0 -> node1 [ color=BLACK, label=< <font point-size='10' color='#336633'>ns1:predicate</font> > ] ;
# eg://org/?foo=bar&baz=bux node0
node0 [ shape=none, color=black label=< <table color='#666666' cellborder='0' cellspacing='0' border='1'><tr><td colspan='2' bgcolor='grey'><B>This & That</B></td></tr><tr><td href='eg://org/?foo=bar&baz=bux' bgcolor='#eeeeee' colspan='2'><font point-size='10' color='#6666ff'>eg://org/?foo=bar&baz=bux</font></td></tr><tr><td align='left'>ns2:title</td><td align='left'>&quot;This &amp; That&quot;</td></tr></table> > ] 
# eg://org/object node1
node1 [ shape=none, color=black label=< <table color='#666666' cellborder='0' cellspacing='0' border='1'><tr><td colspan='2' bgcolor='grey'><B>object</B></td></tr><tr><td href='eg://org/object' bgcolor='#eeeeee' colspan='2'><font point-size='10' color='#6666ff'>eg://org/object</font></td></tr></table> > ] 
}

Which is invalid DOT in several places:

  • <B>This & That</B>
  • eg://org/?foo=bar&baz=bux</font>
blake-regalia pushed a commit to blake-regalia/rdflib that referenced this issue Dec 4, 2020
@white-gecko
Copy link
Member

Your example code is not self contained, should it be to following?

import io
from rdflib import URIRef, Literal, Graph
from rdflib.namespace import DC
from rdflib.tools.rdf2dot import rdf2dot
subj = URIRef('eg://org/?foo=bar&baz=bux')
pred = URIRef('eg://org/predicate')
obj = URIRef('eg://org/object')

g = Graph()
g.add((subj, pred, obj))
g.add((subj, DC.title, Literal('This & That')))
out = io.StringIO()
rdf2dot(g, out, opts={'display'})
print(out.getvalue())

@white-gecko
Copy link
Member

Is this also solved for the hyperrefs (href)?

@blake-regalia
Copy link
Author

Continuing conversation in #1209

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

Successfully merging a pull request may close this issue.

2 participants