* Prevent importing styles with no section. Fixes #687 And prevent issues with existing styles with no section * Revert sections checks for empty array * Add styleJSONseemsValid function * Clean up * Fix eslint nags
This commit is contained in:
parent
b48817fe01
commit
8906cbbb1a
|
@ -1,6 +1,6 @@
|
||||||
/* global styleSectionsEqual prefs download tryJSONparse ignoreChromeError
|
/* global styleSectionsEqual prefs download tryJSONparse ignoreChromeError
|
||||||
calcStyleDigest getStyleWithNoCode debounce chromeLocal
|
calcStyleDigest getStyleWithNoCode debounce chromeLocal
|
||||||
usercss semverCompare
|
usercss semverCompare styleJSONseemsValid
|
||||||
API_METHODS styleManager */
|
API_METHODS styleManager */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -231,14 +231,6 @@
|
||||||
API_METHODS[json.usercssData ? 'installUsercss' : 'installStyle'](newStyle) :
|
API_METHODS[json.usercssData ? 'installUsercss' : 'installStyle'](newStyle) :
|
||||||
newStyle;
|
newStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
function styleJSONseemsValid(json) {
|
|
||||||
return json
|
|
||||||
&& json.sections
|
|
||||||
&& json.sections.length
|
|
||||||
&& typeof json.sections.every === 'function'
|
|
||||||
&& typeof json.sections[0].code === 'string';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function schedule() {
|
function schedule() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* exported styleSectionsEqual styleCodeEmpty calcStyleDigest */
|
/* exported styleSectionsEqual styleCodeEmpty calcStyleDigest styleJSONseemsValid */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function styleCodeEmpty(code) {
|
function styleCodeEmpty(code) {
|
||||||
|
@ -96,3 +96,14 @@ function calcStyleDigest(style) {
|
||||||
return parts.join('');
|
return parts.join('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function styleJSONseemsValid(json) {
|
||||||
|
return json
|
||||||
|
&& json.name
|
||||||
|
&& json.name.trim()
|
||||||
|
&& Array.isArray(json.sections)
|
||||||
|
&& json.sections
|
||||||
|
&& json.sections.length
|
||||||
|
&& typeof json.sections.every === 'function'
|
||||||
|
&& typeof json.sections[0].code === 'string';
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/* global messageBox styleSectionsEqual getOwnTab API onDOMready
|
/* global messageBox styleSectionsEqual getOwnTab API onDOMready
|
||||||
tryJSONparse scrollElementIntoView $ $$ API $create t animateElement */
|
tryJSONparse scrollElementIntoView $ $$ API $create t animateElement
|
||||||
|
styleJSONseemsValid */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const STYLISH_DUMP_FILE_EXT = '.txt';
|
const STYLISH_DUMP_FILE_EXT = '.txt';
|
||||||
|
@ -144,11 +145,7 @@ function importFromString(jsonString) {
|
||||||
.then(done);
|
.then(done);
|
||||||
|
|
||||||
function analyze(item, index) {
|
function analyze(item, index) {
|
||||||
if (typeof item !== 'object' ||
|
if (typeof item !== 'object' || !styleJSONseemsValid(item)) {
|
||||||
!item ||
|
|
||||||
!item.name ||
|
|
||||||
!item.name.trim() ||
|
|
||||||
(item.sections && !Array.isArray(item.sections))) {
|
|
||||||
stats.invalid.names.push(`#${index}: ${limitString(item && item.name || '')}`);
|
stats.invalid.names.push(`#${index}: ${limitString(item && item.name || '')}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user