fixup! foolproof escaping

This commit is contained in:
tophf 2022-07-28 01:59:29 +03:00
parent 84f9d68763
commit 8ca1e3ba70

View File

@ -9,21 +9,20 @@ const usoApi = {
* https://github.com/33kk/uso-archive/blob/flomaster/lib/converters.js * https://github.com/33kk/uso-archive/blob/flomaster/lib/converters.js
*/ */
async toUsercss(data, {metaOnly = true} = {}) { async toUsercss(data, {metaOnly = true} = {}) {
const {user, style_settings: ss = []} = data;
const badKeys = {}; const badKeys = {};
const newKeys = []; const newKeys = [];
const descr = JSON.stringify(data.description.trim()); const descr = JSON.stringify(data.description.trim());
const vars = ss.map(makeVar).join('').replace(/\*\//g, '*\\/'); const vars = (data.style_settings || []).map(makeVar).join('');
const sourceCode = `\ const sourceCode = `\
/* ==UserStyle== /* ==UserStyle==
@name ${data.name} @name ${data.name}
@namespace USO Archive @namespace USO Archive
@version ${data.updated.replace(/-/g, '').replace(/[T:]/g, '.').slice(0, 14)} @version ${data.updated.replace(/-/g, '').replace(/[T:]/g, '.').slice(0, 14)}
@description ${descr.includes('\\') ? descr : descr.slice(1, -1)} @description ${descr.includes('\\') ? descr : descr.slice(1, -1)}
@author ${user && user.name || '?'} @author ${(data.user || {}).name || '?'}
@license ${makeLicense(data.license)}${vars ? '\n@preprocessor uso' + vars : ''} @license ${makeLicense(data.license)}${vars ? '\n@preprocessor uso' + vars : ''}
==/UserStyle== */ `.replace(/\*\//g, '*\\/') +
${newKeys[0] ? useNewKeys(data.css) : data.css}`; `==/UserStyle== */\n${newKeys[0] ? useNewKeys(data.css) : data.css}`;
const res = await usercssMan.build({sourceCode, metaOnly}); const res = await usercssMan.build({sourceCode, metaOnly});
return Object.assign(res, {badKeys, newKeys}); return Object.assign(res, {badKeys, newKeys});