on master help sign in
Escaped
commita61753c48b98493eef6fe76104d67a1b77046659 authorDevine Lu Linvega <aliceffekt@gmail.com> dateWed 3 Jul 2019, 19:53 (7 years ago) parentb3854f8
1 file changed+5−1
scripts/hallway.js+5−1
scripts/hallway.js+5−1
@@ -140,7 +140,7 @@ function Hallway (sites) {
140140 if (line === '') { continue }
141141 const parts = line.replace(' ', '\t').split('\t')
142142 const date = parts[0].trim()
143− const body = parts[1].trim()
143+ const body = escapeHtml(parts[1].trim()).trim()
144144 const channel = body.substr(0, 1) === '/' ? body.split(' ')[0].substr(1).toLowerCase() : null
145145 const offset = new Date() - new Date(date)
146146 entries.push({ date, body, author, offset, channel })
@@ -174,4 +174,8 @@ function Hallway (sites) {
174174
175175 return `${Math.floor(minutes / 1440)} days ago`
176176 }
177+
178+ function escapeHtml(unsafe) {
179+ return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
180+ }
177181}