Skip to content

Commit 8113d9c

Browse files
Revert "fix: logs for testing"
This reverts commit 7247ee7.
1 parent 7247ee7 commit 8113d9c

File tree

4 files changed

+5
-60
lines changed

4 files changed

+5
-60
lines changed

packages/scratch-svg-renderer/src/sanitize-svg.js

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ const DOMPurify = require('isomorphic-dompurify');
88

99
const sanitizeSvg = {};
1010

11-
const isInternalRef = ref => ref.startsWith('#') || ref.startsWith('data:');
12-
1311
DOMPurify.addHook(
1412
'beforeSanitizeAttributes',
1513
currentNode => {
1614

1715
if (currentNode && currentNode.href && currentNode.href.baseVal) {
1816
const href = currentNode.href.baseVal.replace(/\s/g, '');
1917
// "data:" and "#" are valid hrefs
20-
if (!isInternalRef(href)) {
21-
// TODO: Those can be in different namespaces than `xlink:`
18+
if ((href.slice(0, 5) !== 'data:') && (href.slice(0, 1) !== '#')) {
19+
2220
if (currentNode.attributes.getNamedItem('xlink:href')) {
2321
currentNode.attributes.removeNamedItem('xlink:href');
2422
delete currentNode['xlink:href'];
@@ -29,24 +27,6 @@ DOMPurify.addHook(
2927
}
3028
}
3129
}
32-
33-
// Remove url(...) usages with external references
34-
if (currentNode && currentNode.attributes) {
35-
for (let i = currentNode.attributes.length - 1; i >= 0; i--) {
36-
const attr = currentNode.attributes[i];
37-
const rawValue = attr.value || '';
38-
const value = rawValue.toLowerCase().replace(/\s/g, '');
39-
40-
const urlMatch = value.match(/url\((.+?)\)/);
41-
if (urlMatch) {
42-
const ref = urlMatch[1].replace(/['"]/g, '');
43-
if (!isInternalRef(ref)) {
44-
currentNode.removeAttribute(attr.name);
45-
}
46-
}
47-
}
48-
}
49-
5030
return currentNode;
5131
}
5232
);
@@ -57,34 +37,13 @@ DOMPurify.addHook(
5737
if (data.tagName === 'style') {
5838
const ast = parse(node.textContent);
5939
let isModified = false;
60-
40+
// Remove any @import rules as it could leak HTTP requests
6141
walk(ast, (astNode, item, list) => {
62-
// @import rules
63-
if (astNode.type === 'Atrule' && astNode.name.toLowerCase() === 'import') {
42+
if (astNode.type === 'Atrule' && astNode.name === 'import') {
6443
list.remove(item);
6544
isModified = true;
6645
}
67-
68-
// Elements using url(...) for external resources
69-
if (astNode.type === 'Declaration' && astNode.value) {
70-
let shouldRemove = false;
71-
walk(astNode.value, valueNode => {
72-
if (valueNode.type === 'Url') {
73-
const urlValue = (valueNode.value.value || '').trim().replace(/['"]/g, '');
74-
75-
if (!isInternalRef(urlValue)) {
76-
shouldRemove = true;
77-
}
78-
}
79-
});
80-
81-
if (shouldRemove) {
82-
list.remove(item);
83-
isModified = true;
84-
}
85-
}
8646
});
87-
8847
if (isModified) {
8948
node.textContent = generate(ast);
9049
}

packages/scratch-vm/src/import/load-costume.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ const loadCostumeFromAsset = function (costume, runtime, optVersion) {
356356
* @returns {?Promise} - a promise which will resolve after skinId is set, or null on error.
357357
*/
358358
const loadCostume = function (md5ext, costume, runtime, optVersion) {
359-
console.log('CCCCCCCCCCCCCCCCCCCCCCCCCCCC');
360-
console.log(md5ext);
361359
const idParts = StringUtil.splitFirst(md5ext, '.');
362360
const md5 = idParts[0];
363361
const ext = idParts[1].toLowerCase();
@@ -396,8 +394,6 @@ const loadCostume = function (md5ext, costume, runtime, optVersion) {
396394
if (assetArray[0]) {
397395
costume.asset = assetArray[0];
398396
} else {
399-
console.log('BBBBBBBBBBBBBBBBBBBBBBBBBBB');
400-
console.log(md5ext);
401397
return handleCostumeLoadError(costume, runtime);
402398
}
403399

@@ -409,8 +405,6 @@ const loadCostume = function (md5ext, costume, runtime, optVersion) {
409405
.catch(error => {
410406
// Handle case where storage.load rejects with errors
411407
// instead of resolving null
412-
console.log('AAAAAAAAAAAAAAAAAAAAAAAA');
413-
console.log(md5ext);
414408
log.warn('Error loading costume: ', error);
415409
return handleCostumeLoadError(costume, runtime);
416410
});

packages/scratch-vm/src/serialization/sb2.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,6 @@ const parseScratchAssets = function (object, runtime, topLevel, zip) {
452452
if (costumeSource.textLayerMD5) {
453453
costume.textLayerMD5 = StringUtil.splitFirst(costumeSource.textLayerMD5, '.')[0];
454454
}
455-
console.log('////////////////////////////');
456-
console.log('sb2: old md5');
457-
console.log(costume.md5);
458-
console.log('////////////////////////////');
459455
// If there is no internet connection, or if the asset is not in storage
460456
// for some reason, and we are doing a local .sb2 import, (e.g. zip is provided)
461457
// the file name of the costume should be the baseLayerID followed by the file ext

packages/scratch-vm/src/serialization/sb3.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,13 @@ const parseScratchAssets = function (object, runtime, zip) {
894894
costumeSource.md5ext : `${costumeSource.assetId}.${dataFormat}`;
895895
costume.md5 = costumeMd5Ext;
896896
costume.dataFormat = dataFormat;
897-
console.log('////////////////////////////');
898-
console.log('sb3: old md5');
899-
console.log(costumeMd5Ext);
900-
console.log('////////////////////////////');
901897
// deserializeCostume should be called on the costume object we're
902898
// creating above instead of the source costume object, because this way
903899
// we're always loading the 'sb3' representation of the costume
904900
// any translation that needs to happen will happen in the process
905901
// of building up the costume object into an sb3 format
906902
return deserializeCostume(costume, runtime, zip)
907-
.then(() => loadCostume(costume.md5, costume, runtime));
903+
.then(() => loadCostume(costumeMd5Ext, costume, runtime));
908904
// Only attempt to load the costume after the deserialization
909905
// process has been completed
910906
});

0 commit comments

Comments
 (0)