Skip to content

Commit

Permalink
Change approach to shadowing "toString" property for escapeXML
Browse files Browse the repository at this point in the history
  • Loading branch information
jportner committed Mar 10, 2023
1 parent f818bce commit 58bc2eb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ exports.escapeXML = function (markup) {
: String(markup)
.replace(_MATCH_HTML, encode_char);
};
exports.escapeXML.toString = function () {

// If the Object prototype is frozen, the "toString" property is non-writable. This means that any objects which inherit this property
// cannot have the property changed using an assignment. If using strict mode, attempting that will cause an error. If not using strict
// mode, attempting that will be silently ignored.
// However, we can still explicitly shadow the prototype's "toString" property by defining a new "toString" property on this object.
Object.defineProperty(exports.escapeXML, 'toString', function () {
return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
};
});

/**
* Naive copy of properties from one object to another.
Expand Down

0 comments on commit 58bc2eb

Please sign in to comment.