I extend a JavaScript application. I do not need nice styles. I only want to allow users to enter a text. This text is not stored anywhere (it may be printed out). In my search I found window.prompt. Now I'm wondering if this is safe.
I escaped the most important characters.This is the relevant part of my code:
_fireCreatedEvent: function () {
var input = window.prompt("", "");
var text = this._escapeHtml(input);
var ticon = L.divIcon({
iconSize: null,
html: '<div class="map-label"><div class="map-label-content">' + text + '</div><div class="map-label-arrow"></div></div>'
});
var textmarker = new L.Marker.Touch(this._textmarker.getLatLng(), {icon: ticon});
L.Draw.Feature.prototype._fireCreatedEvent.call(this, textmarker);
},
...
_escapeHtml(perhapsunsafe) {
return perhapsunsafe
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/&/g, "&")
.replace(/"/g, """)
.replace(/'/g, "'");
}
Is this code safe enough to use on the internet?