Skip to content

Commit

Permalink
Overwriting Annex B String.prototype HTML methods in IE 9, which both…
Browse files Browse the repository at this point in the history
… uppercases the tag names, and fails to escape double quotes.
  • Loading branch information
ljharb committed Feb 18, 2015
1 parent c23133d commit a0e0544
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@
},

CreateHTML: function (string, tag, attribute, value) {
var S = ES.ToString(string);
var S = String(string);
var p1 = '<' + tag;
if (attribute !== '') {
var V = ES.toString(value);
var V = String(value);
var escapedV = V.replace(/"/g, '&quot;');
p1 += ' ' + attribute + '="' + escapedV + '"';
}
Expand Down Expand Up @@ -2503,7 +2503,7 @@

// Annex B HTML methods
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-additional-properties-of-the-string.prototype-object
defineProperties(String.prototype, {
var stringHTMLshims = {
anchor: function anchor(name) { return ES.CreateHTML(this, 'a', 'name', name); },
big: function big() { return ES.CreateHTML(this, 'big', '', ''); },
blink: function blink() { return ES.CreateHTML(this, 'blink', '', ''); },
Expand All @@ -2517,6 +2517,13 @@
strike: function strike(url) { return ES.CreateHTML(this, 'strike', '', ''); },
sub: function sub(url) { return ES.CreateHTML(this, 'sub', '', ''); },
sup: function sub(url) { return ES.CreateHTML(this, 'sup', '', ''); }
};
defineProperties(String.prototype, stringHTMLshims);
Object.keys(stringHTMLshims).forEach(function (key) {
var output = String.prototype[key].call('', '"');

This comment has been minimized.

Copy link
@rwaldron

rwaldron Feb 18, 2015

Contributor

There was as bug report in https://gitter.im/tableflip/nodebot-workshop re: this line

/Users/jloi/code/cours/nodeschool/nodebot-workshop/node_modules/johnny-five/node_modules/es6-shim/es6-shim.js:2536
    var output = String.prototype[key].call('', ' " ');

cc @gorhgorh

if (output !== output.toLowerCase()) {
defineProperty(String.prototype, key, stringHTMLshims[key], true);
}
});

return globals;
Expand Down

0 comments on commit a0e0544

Please sign in to comment.