Node.js based forum software built for the modern web
Fixes #6259
Julian Lamf6ad344ac6fd
diff --git a/src/upgrades/1.7.0/generate-custom-html.js b/src/upgrades/1.7.0/generate-custom-html.jsindex 5de0238920..914454a4c2 100644--- a/src/upgrades/1.7.0/generate-custom-html.js+++ b/src/upgrades/1.7.0/generate-custom-html.js@@ -1,37 +1,45 @@'use strict';+var db = require('../../database');var meta = require('../../meta');module.exports = {name: 'Generate customHTML block from old customJS setting',timestamp: Date.UTC(2017, 9, 12),method: function (callback) {- var newHTML = meta.config.customJS;- var newJS = [];+ db.getObjectField('config', 'customJS', function (err, newHTML) {+ if (err) {+ return callback(err);+ }++ var newJS = [];++ // Forgive me for parsing HTML with regex...+ var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;+ var match = scriptMatch.exec(newHTML);- // Forgive me for parsing HTML with regex...- var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;- var match = scriptMatch.exec(newHTML);+ while (match) {+ if (match[1]) {+ // Append to newJS array+ newJS.push(match[1].trim());- while (match) {- if (match[1]) {- // Append to newJS array- newJS.push(match[1].trim());+ // Remove the match from the existing value+ newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();+ }- // Remove the match from the existing value- newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();+ match = scriptMatch.exec(newHTML);}- match = scriptMatch.exec(newHTML);- }+ // Combine newJS array+ newJS = newJS.join('\n\n');- // Combine newJS array- newJS = newJS.join('\n\n');+ console.log('wut', newJS, 'and', newHTML);- // Write both values to config- meta.configs.setMultiple({- customHTML: newHTML,- customJS: newJS,- }, callback);+ // Write both values to config+ meta.configs.setMultiple({+ customHTML: newHTML,+ customJS: newJS,+ }, callback);+ });},};