Advanced Compilation Error - perhaps in the HTML Sanitizer or in my code?

82 views
Skip to first unread message

Lillian at Ysight

unread,
Sep 17, 2017, 8:42:27 PM9/17/17
to Closure Library Discuss

Hello.  After updating to the latest closure library, I get a RUN-Time error (not a compiler time error).  Screen shot of the chrome debugger is above.
I do use the sanitizer as 
var mySanitizer =
    new goog.html.sanitizer.HtmlSanitizer.Builder()
.withCustomNetworkRequestUrlPolicy(goog.html.SafeUrl.sanitize)// lose the id?
.allowCssStyles()
.allowFormTag()
.addOriginalTagNames() 
.withCustomTokenPolicy(goog.functions.identity) // so id= can be used and styles
.allowDataAttributes([ "data-id","data-name" ]) //data-* attributes are inert as per HTML5 specs
.build();
goog.exportSymbol ('toolbox.utils.mySanitizer', mySanitizer) ;


and later I use
areYouSureDialog.setSafeHtmlContent(toolbox.utils.mySanitizer.sanitize(htmlAreYouSure));

The full function that is returned by the advanced compilation is listed below.  Does anyone see the error in my code or the closure library.  The line the debugger complains about for the Type Error is in large font and highlighted.

 Thank you very much for your help.

function kj(a, b) {
    var c = document.createElement("span");
    if (!Pi || !b)
        return c;
    try {
        var d = document.createElement("template");
        if ("content"in d) {
            d.innerHTML = b;
            var e = d.content
        } else {
            var f = document.implementation.createHTMLDocument("x");
            e = f.body;
            f.body.innerHTML = b
        }
        var h = document.createTreeWalker(e, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, null, !1)
    } catch (St) {
        return c
    }
    b = {};
    for (e = 0; f = h.nextNode(); ) {
        e++;
        var d = a;
        if (3 == f.nodeType)
            d = document.createTextNode(f.data);
        else {
            var k = gj(f).toUpperCase()
              , l = !1
              , n = !1;
            if (k in Gi || k in d.g) {
                var p = "template";
                n = !0
            } else
                d.j[k] ? p = k : (p = "span",
                l = !0);
            p = document.createElement(p);
            d.c && l && ej(p, "data-sanitizer-original-tag", k.toLowerCase());
            n && ej(p, "data-sanitizer-blacklisted-tag", "");
            d = p
        }
        if (3 != d.nodeType) {
            var k = a, l = f, n = d, q;
            p = l;
            if (q = (q = Ri.attributes) && q.get ? q.get.apply(p) : p.attributes instanceof NamedNodeMap ? p.attributes : null)
                for (var r = 0; p = q[r]; r++)
                    if (p.specified) {
                        var t = k;
                        var x = l
                          , N = p
                          , I = N.name;
                        if (Ka(I, "data-sanitizer-"))
                            t = null;
                        else {
                            var Ca = gj(x)
                              , N = N.value
                              , y = {
                                tagName: z(Ca).toLowerCase(),
                                attributeName: z(I).toLowerCase()
                            }
                              , Ji = {
                                Zc: void 0
                            };
                            if ("style" == y.attributeName) {
                                var Ki = Ri.style
                                  , x = x instanceof HTMLElement && Ki && Ki.get ? Ki.get.apply(x) : x.style instanceof CSSStyleDeclaration ? x.style : null;
                                Ji.Zc = x
                            }
                            Ca = dj(Ca, I);
                            Ca in t.a ? (t = t.a[Ca],
                            t = t(N, y, Ji)) : (I = dj(null, I),
                            I in t.a ? (t = t.a[I],
                            t = t(N, y, Ji)) : t = null)
                        }
                        null === t || ej(n, p.name, t)
                    }
            b[e] = d;
            ej(f, "data-sanitizer-elem-num", String(e))
        }
        k = gj(f);
        Qi && "template" === k.toLowerCase() && !d.hasAttribute("data-sanitizer-blacklisted-tag") && mj(a, f, d);
        f = hj(f);
        k = !1;
        if (null === f)
            k = !0;
        else if ("body" == gj(f).toLowerCase() || 11 == f.nodeType)
            l = hj(f),
            11 == f.nodeType && null === l ? k = !0 : "body" == gj(f).toLowerCase() && (l = hj(l),
            null === hj(l) && (k = !0));
        k || !f ? f = c : (f = (k = Element.prototype.getAttribute) && f instanceof Element ? k.call(f, "data-sanitizer-elem-num") || "" : "",
        f = b[f]);
        f.content && (f = f.content);
        ya(d) && 1 == d.nodeType && d.hasAttribute("data-sanitizer-blacklisted-tag") || f.appendChild(d)
    }
    return c
}



Lillian at Ysight

unread,
Sep 19, 2017, 7:30:06 PM9/19/17
to Closure Library Discuss
Please note:  this is a run-time error!  The compilation works correctly.  Thank you in advance.

Steve Hicks

unread,
Sep 19, 2017, 8:09:32 PM9/19/17
to Closure Library Discuss
Without seeing any uncompiled source code, it's very difficult to have any idea what could be going wrong.  Can you remove any extraneous lines of code (such that the error still persists) and post both the uncompiled and compiled versions?

Typically this sort of thing is caused by using a property unquoted that needed to be quoted, or by an inaccurate cast causing the compiler to think a variable is the wrong type.  But without seeing original code, it's hard to say.  Sometimes, in putting together a minimal example of the problem, you can even end up figuring out what's wrong yourself.

--

---
You received this message because you are subscribed to the Google Groups "Closure Library Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-library-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Y sight LLC

unread,
Sep 19, 2017, 8:15:35 PM9/19/17
to closure-lib...@googlegroups.com
Hello,

Thank you for your response.
I have narrowed it down to the following lines of code.  I have never really “coded” a variable like this in an google-api-client export and clearly it does not work.  I have done it with function successfully
Would you happen to know how you “externalize” an object that has attributes that are functions for the good compilation?

Thank you,

Lillian

var mySanitizer =
    new goog.html.sanitizer.HtmlSanitizer.Builder()
.withCustomNetworkRequestUrlPolicy(goog.html.SafeUrl.sanitize)// lose the id?
.allowCssStyles()
.allowFormTag()
.addOriginalTagNames() 
.withCustomTokenPolicy(goog.functions.identity) // so id= can be used and styles
.allowDataAttributes([ "data-id","data-name" ]) //data-* attributes are inert as per HTML5 specs
.build();
goog.exportSymbol ('toolbox.utils.mySanitizer', mySanitizer) ;
goog.exportSymbol ('toolbox.utils.mySanitizer.sanitize', mySanitizer.sanitize) ;

signInDialog = new goog.ui.Dialog(null, USE_IFRAME);

signInDialog.setSafeHtmlContent(toolbox.utils.mySanitizer.sanitize(htmlLogin));  <—  problem line does not understand “sanitize” function - 

Steve Hicks

unread,
Sep 19, 2017, 9:17:21 PM9/19/17
to Closure Library Discuss

Ah, sanitize is an instance property, so exportSymbol won’t work: you need to use goog.exportProperty for properties.

goog.exportProperty(goog.html.sanitizer.HtmlSanitizer.prototype, 'sanitize', goog.html.sanitizer.HtmlSanitizer.prototype.sanitize);

--

---
You received this message because you are subscribed to the Google Groups "Closure Library Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-library-discuss+unsubscr...@googlegroups.com.

Y sight LLC

unread,
Sep 19, 2017, 10:55:44 PM9/19/17
to closure-lib...@googlegroups.com
Thanks!
You received this message because you are subscribed to a topic in the Google Groups "Closure Library Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/closure-library-discuss/8oGjSUUJkQI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to closure-library-d...@googlegroups.com.

Lillian at Ysight

unread,
Sep 20, 2017, 8:05:03 AM9/20/17
to Closure Library Discuss


On Sunday, September 17, 2017 at 8:42:27 PM UTC-4, Lillian at Ysight wrote:
Error was in my code in the way I did my export.  Thank you for your help.

Reply all
Reply to author
Forward
0 new messages