Skip to content

Commit

Permalink
Fix escapeHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwieds committed Mar 21, 2023
1 parent c0f4217 commit 8283912
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 22 deletions.
72 changes: 69 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,70 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
.firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Mac generated files
.DS_Store
node_modules
lib-old
package-lock.json

# Custom
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,11 @@ function Manager() {
This.properties.page.status.initializing = true;

// set other properties
This.properties.meta.environment = /((:\/\/)(local|127\.|192\.|.+ngrok\.))/.test(window.location.href) ? 'development' : 'production';

This.properties.meta.environment = window.location.host.match(/:40|ngrok/)
? 'development'
: 'production';

// Load polyfills
init_loadPolyfills(This, configuration, function() {
This.properties.page.status.initializing = false;
// This.properties.genericPromise = new Promise(resolve => { resolve() });
Expand Down
41 changes: 28 additions & 13 deletions lib/utilities.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
/*
*/

var htmlEscapeMap = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
};
var shadow;

function Utilities(utilObj) {
this.utilities = utilObj;
Expand Down Expand Up @@ -74,9 +65,33 @@ Utilities.clipboardCopy = function (input) {
}

// Escape HTML
Utilities.escapeHTML = function (string) {
return (string || '').replace(/[&<>"'`=\/]/g, function (s) {
return htmlEscapeMap[s];
// https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript
// Utilities.escapeHTML = function (str) {
// shadow = shadow || document.createElement('div');
// shadow.textContent = str;

// return shadow.textContent.replace(/["']/g, function(m) {
// switch (m) {
// case '"':
// return '&quot;';
// default:
// return '&#039;';
// }
// });
// }

Utilities.escapeHTML = function (str) {
shadow = shadow || document.createElement('p');
shadow.innerHTML = '';
shadow.appendChild(document.createTextNode(str));

return shadow.innerHTML.replace(/["']/g, function(m) {
switch (m) {
case '"':
return '&quot;';
default:
return '&#039;';
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-manager",
"version": "3.1.23",
"version": "3.1.25",
"description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,4 +28,4 @@
"firebase": "^8.10.1",
"lazysizes": "^5.3.2"
}
}
}

0 comments on commit 8283912

Please sign in to comment.