Skip to content

Commit

Permalink
Simplified Refresh "New Details?" Comparison
Browse files Browse the repository at this point in the history
Side effect of this system is a bug fix where event names/locations with certain characters would continually flash and update upon every refresh
  • Loading branch information
Leo authored Jul 17, 2017
1 parent 898942f commit 7b3a35c
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/freebusy.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,17 @@
eventLocation = eventName;
}

// sanitize the string
// also sanitize the last string, so we can compare and look for changes next
if (eventLocation) {
eventLocation = sanitizeHTML(eventLocation);
lastLocation = sanitizeHTML(lastLocation);
// if there's no event name or location
if (!eventLocation) {
eventLocation = "Busy";
}

// turn the HTML-ified lastLocation from the DOM back into the original string
lastLocation = desanitizeHTML(lastLocation);

// if the event details haven't changed from the last check to now, finish this row and move on
if (((lastLocation.includes(eventName) || lastLocation.includes(eventLocation)) || (!eventName && !eventLocation)) && lastDuration == eventDuration) {
if ((lastLocation == eventName || lastLocation == eventLocation) && lastDuration == eventDuration) {

return;

} else { // new details have come to light
Expand All @@ -252,6 +253,9 @@
thisPersonsRow.cells[0].innerHTML += '<span class="label label-danger animated flash">' + personsExt + '</span> ';
}
thisPersonsRow.cells[0].innerHTML += personsName;
// before we put the original string into the DOM,
// sanitize it so people can't put rogue HTML in their names
eventLocation = sanitizeHTML(eventLocation);
thisPersonsRow.cells[1].innerHTML = eventLocation;
thisPersonsRow.cells[2].innerHTML = eventDuration;

Expand All @@ -263,8 +267,33 @@

// http://stackoverflow.com/a/12034334
function sanitizeHTML(string) {
var entityMap = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;', '/': '&#x2F;', '`': '&#x60;', '=': '&#x3D;'};
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
var entityMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"'": "&#39;",
"/": "&#x2F;",
"`": "&#x60;",
"=": "&#x3D;"
};
return String(string).replace(/[&<>"'`=\/]/g, function(s) {
return entityMap[s];
});
}

function desanitizeHTML(string) {
var entityMap = {
"&amp;": "&",
"&lt;": "<",
"&gt;": ">",
"&quot;": "\"",
"&#39;": "'",
"&#x2F;": "/",
"&#x60;": "`",
"&#x3D;": "="
};
return String(string).replace(/(&amp;|&lt;|&gt;|&quot;|&#39;|&#x2F;|&#x60;|&#x3D;)/g, function(s) {
return entityMap[s];
});
}
Expand Down

0 comments on commit 7b3a35c

Please sign in to comment.