uibinder/safehtml disagreement on xlink:href attribute

81 views
Skip to first unread message

Stephen Haberman

unread,
Nov 18, 2015, 9:49:03 AM11/18/15
to google-web-toolkit-contributors
I'm attempting to use icons in an svg file in a ui.xml file like:

    <svg><use xlink:href=/icons.svg#foo-icon /></svg>

But with a variable, so:

    <svg><use xlink:href="{someExpression}" /></svg>

However, because of the xlink namespace (which the browser requires, AFAICT), UiBinder and SafeHtml end up disagreeing on whether this is a SafeUri-requiring attribute.

E.g. here is the UiBinder logic, which ignores namespace because it uses local name:


And here is the SafeHtml logic, which does looks at namespace+attribute due to the underlying jsilver implementation:



So, it ends up failing because UiBinder generated SafeUri, but SafeHtml says "this attribute shouldn't be a SafeUri, did you SafeHtml or String".

I'm wondering how to make them agree...while in this scenario it is true that xlink:href is a URI, so UiBinder was right, in theory there could be other namespaces where that is not the case, and the heuristic of "any attribute named href is a uri, regardless of namespace" could be wrong.

Any great ideas?

...I suppose the other option is to just turn off safe html templates for now.

- Stephen



Thomas Broyer

unread,
Nov 19, 2015, 5:28:21 AM11/19/15
to GWT Contributors
Well, three things:
  • There's an impedance mismatch between UiBinder (using XML with namespaces) and HTML. UiBinder has not been designed to output "namespaced HTML", and actually there's no such thing as "namespaced HTML" (SVG-in-HTML hardcodes the "xlink:href" name to translate to an "href" attribute in the XLink namespace in the InfoSet: https://html.spec.whatwg.org/multipage/syntax.html#adjust-foreign-attributes). To have UiBinder play well in those cases, it'd have to somehow follow the "InfoSet to HTML syntax" rules: https://html.spec.whatwg.org/multipage/syntax.html#serialising-html-fragments
  • UiBinder should probably converge to use jsilver's HtmlUtils.isAttributeUri and co. so we at least have the same rule everywhere.
  • JSilver should adjust to those special cases like "xhtml:href", and UiBinder should pass the appropriate name to JSilver (following the same "InfoSet to HTML syntax" mapping rules).
That doesn't look like an big effort (though too late for 2.8 I'm afraid…)
Reply all
Reply to author
Forward
0 new messages