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

Problem with special characters and HTML entities #432

Closed
elfakamal opened this issue Feb 24, 2014 · 2 comments
Closed

Problem with special characters and HTML entities #432

elfakamal opened this issue Feb 24, 2014 · 2 comments

Comments

@elfakamal
Copy link

Hi, I have a little problem displaying some special characters.

I have a dummy element that I called polymer-label, it's an extended bootstrap label with a button.

<link rel="import" href="../bower_components/polymer/polymer.html">

<polymer-element name="polymer-label" attributes="labelType">
  <template extend="span">
    <style>
      /* styles for the custom element itself - lowest specificity */
      :host {
        /*display: block;*/
      }

      span.label {
        border-bottom-right-radius: 0px;
        border-top-right-radius: 0px;
        display: inline;
      }

      #button-remove {
        border-bottom-left-radius: 0px;
        border-top-left-radius: 0px;

        top: 0px;
        height: 18px;
        outline: none;
      }

      /*
      style if an ancestor has the different class
      :host(.different) { }
      */
    </style>
    <span class="label label-{{labelType}}">
      {{innerHTML}}
    </span>
    <button id="button-remove" class="btn btn-xs btn-{{labelType}} glyphicon glyphicon-remove"></button>
  </template>
  <script>
    Polymer('polymer-label', {
      //applyAuthorStyles: true,
      //resetStyleInheritance: true,

      // element is fully prepared
      ready: function(){ },
      // instance of the element is created
      created: function() { },
      // instance was inserted into the document
      enteredView: function() { },
      // instance was removed from the document
      leftView: function() { },
      // attribute added, removed or updated
      attributeChanged: function(attrName, oldVal, newVal) { }
    });
  </script>
</polymer-element>

the problem is when I use special characters like & or < :

<polymer-label labelType="success">hello & world</polymer-label>

the element converts them to HTML entities:
screen shot 2014-02-25 at 00 13 58

Can someone help me on this ? thx.

@sjmiles
Copy link
Contributor

sjmiles commented Feb 24, 2014

The proper method for displaying light-dom content (instead of {{innerHTML}}) is with a content node.

<span class="label label-{{labelType}}">
  <content></content>
</span>

In general, bindings won't let you pass unescaped HTML content to help prevent XSS attacks.

@elfakamal
Copy link
Author

so cool :-)
Thank you very much @sjmiles

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

No branches or pull requests

2 participants