Is there the a way to prevent HTML escaping inside a Polymer expression? [duplicate]

孤人 提交于 2019-12-22 08:55:35

问题


My colleague Patrick & I currently converting an autocomplete component from Web UI to Polymer.dart.In Web UI we provided a HTML rendered list to the autocomplete in order to give a programmer the opportunity to style the results. Based on the input's value we filtered the list and displayed the matching results.

What would you recommend to achieve the same behaviour in Polymer.dart? Should we approach this completly differently?

Old Web UI code:

<template iterate="entry in filteredEntries">
  <li class="b-autocomplete-results-li">{{ entry.sanitizedHtml }}</li>
</template>

Class for one entry:

class AutocompleteEntry {

  final String id;
  final String searchableText;
  final Element _element;

  AutocompleteEntry(this.id, this.searchableText, this._element) {
    // remove the data-id and data-text since we don't need them in the html
    _element.dataset.remove('text');
    _element.dataset.remove('id');
  }

  get sanitizedHtml {
    var validator = new NodeValidatorBuilder()..allowHtml5();
    var documentFragment = document.body.createFragment(_element.outerHtml, validator: validator);
    return documentFragment;
  }
}

回答1:


Update

A ready-to-use element for Dart Polymer 1.0 is bwu-bind-html


No there isn't. This is intentional because it is prone to XSS attacks. What you can do is to use an element like <safe-html> instead.

My answer to this question HTML Tags Within Internationalized Strings In Polymer.dart shows the full source code.



来源:https://stackoverflow.com/questions/25058638/is-there-the-a-way-to-prevent-html-escaping-inside-a-polymer-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!