Introducing the CSP Fixer

@devoncarew

Devon: sorry, a couple of unrelated trivial changes have crept in.

I should also add tests.

Also note that I deliberately exposed the feature only in the form of an explicit action. I didn't want to build it into the Bower install/update sequence or anything like that because it's too early and too risky.

Wow, John, so html5lib is yours? Cool stuff!

I've tried out parseFragment(): it does *exactly *what's needed for Polymer
elements, couldn't improve a thing (doesn't insert anything extra and
doesn't eat some new-lines, unlike parse()). Unfortunately, it breaks
regular HTMLs (removes <head>, <body> etc. and outputs the contained nodes
as a single stream).

It would be great to add a flag to parse() to preserve the original
structure as much as possible. Did you mean for us to contribute that, or
were you volunteering to do that yourself?

Alternatively, if you suggested a reliable way to tell Polymer flavor of
HTML from a regular one, that could be a stop-gap solution for now. But
then again, all this is not a must, just a nice-to-have.


On Tue, Aug 5, 2014 at 3:17 PM, John Messerly <notifications@github.com>
wrote:

> In ide/app/lib/refactor/csp_fixer.dart:
>
> > +      }
> > +
> > +      _outlineScripts();
> > +      _outlineEventHandlers();
> > +      // TODO(ussuri): Fix other known and fixable CSP violations.
> > +
> > +      // If there are any files to write, the original HTML has been altered:
> > +      // Back up the original HTML and replace it with the postprocessed one.
> > +      if (_newFiles.isNotEmpty) {
> > +        _newFiles.add(
> > +            new _FileWriter(_file.parent, _file.name + '.pre_csp', htmlText));
> > +        // NOTE: doc.outerHtml may insert previously missing parts of a standard
> > +        // HTML document. One important example is Polymer elements, which
> > +        // normally don't have <head> or <body>, but will after postprocessing.
> > +        // That doesn't affect their functionality, though, so it's ok.
> > +        _newFiles.add(
>
> btw, you can use parseFragment
> <http://www.dartdocs.org/documentation/html5lib/0.12.0/index.html#html5lib/parser%23id_parseFragment>
> to have something parse in a different context. That's more or less how
> innerHTML works.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/dart-lang/chromedeveditor/pull/3067/files#r15845834>.
>