Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: npm
- run: npm ci
- run: npm run test:lint
Expand Down
14 changes: 1 addition & 13 deletions lib/sb3_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
{"type": "null"}
]
},
"optionalJSON": {
"oneOf": [
{"type": "object"},
{"type": "array"}
]
},
"boolOrOptBoolString": {
"oneOf": [
{"type": "string",
Expand All @@ -35,13 +29,7 @@
{"type": "number"}
]
},
"scalarVal": {
"oneOf": [
{"$ref":"#/definitions/optionalJSON"},
{"$ref":"#/definitions/stringOrNumber"},
{"type": "boolean"}
]
},
"scalarVal": {},
"assetId": {
"type": "string",
"pattern": "^[a-fA-F0-9]{32}$"
Expand Down
5 changes: 4 additions & 1 deletion lib/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ module.exports = function (input, isSprite, callback) {

// If not legacy or zip, convert buffer to UTF-8 string and return
if (!isZip && !isLegacy) {
return callback(null, [input.toString('utf-8'), null]);
// In browsers, the native TextDecoder can handle much larger values than the JavaScript polyfill for
// Buffer.toString('utf-8'), particularly in Chrome.
const decoder = new TextDecoder();
return callback(null, [decoder.decode(input), null]);
}

// Return error if legacy encoding detected
Expand Down
4 changes: 3 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ module.exports = function (isSprite, input, callback) {
// eslint-disable-next-line global-require
var sb3fix = require('@turbowarp/sb3fix');

var fixed = sb3fix.fixJSON(input);
var fixed = sb3fix.fixJSON(input, {
platform: 'turbowarp'
});
validate(isSprite, fixed, function (err2, result2) {
if (err2) {
// Original validation error will be most useful
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@turbowarp/json": "^0.1.1",
"@turbowarp/jszip": "^3.11.0",
"@turbowarp/sb3fix": "^0.3.0",
"@turbowarp/sb3fix": "^0.4.0",
"ajv": "6.3.0",
"pify": "4.0.1"
},
Expand Down
95 changes: 95 additions & 0 deletions test/fixtures/tw_non_scalar_variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"targets": [
{
"isStage": true,
"name": "Stage",
"variables": {
"8Ct!xBe$u3!.nz_Bh/]#": [
"object",
{
"hello": "world"
}
]
},
"lists": {
"u(}PhnFj*Oe*`Ka~{hhc": [
"list of objects",
[
{
"a": 1
},
{
"b": 2
}
]
]
},
"broadcasts": {},
"blocks": {},
"comments": {},
"currentCostume": 0,
"costumes": [
{
"name": "backdrop1",
"dataFormat": "svg",
"assetId": "cd21514d0531fdffb22204e0ec5ed84a",
"md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg",
"rotationCenterX": 240,
"rotationCenterY": 180
}
],
"sounds": [],
"volume": 100,
"layerOrder": 0,
"tempo": 60,
"videoTransparency": 50,
"videoState": "on",
"textToSpeechLanguage": null
}
],
"monitors": [
{
"id": "8Ct!xBe$u3!.nz_Bh/]#",
"mode": "default",
"opcode": "data_variable",
"params": {
"VARIABLE": "object"
},
"spriteName": null,
"value": 0,
"width": 0,
"height": 0,
"x": 5,
"y": 5,
"visible": true,
"sliderMin": 0,
"sliderMax": 100,
"isDiscrete": true
},
{
"id": "u(}PhnFj*Oe*`Ka~{hhc",
"mode": "list",
"opcode": "data_listcontents",
"params": {
"LIST": "list of objects"
},
"spriteName": null,
"value": [],
"width": 0,
"height": 0,
"x": 5,
"y": 32,
"visible": true
}
],
"extensions": [],
"meta": {
"semver": "3.0.0",
"vm": "0.2.0",
"agent": "",
"platform": {
"name": "TurboWarp",
"url": "https://turbowarp.org/"
}
}
}
23 changes: 23 additions & 0 deletions test/integration/tw_non_scalar_variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const test = require('tap').test;
const fs = require('fs');
const path = require('path');
const parser = require('../../index');

test('non scalar variables', function (t) {
const fixture = fs.readFileSync(path.join(__dirname, '../fixtures/tw_non_scalar_variables.json'), 'utf-8');
parser(fixture, false, function (err, result) {
t.equal(err, null);
t.same(result[0].targets[0].variables['8Ct!xBe$u3!.nz_Bh/]#'][1], {
hello: 'world'
});
t.same(result[0].targets[0].lists['u(}PhnFj*Oe*`Ka~{hhc'][1], [
{
a: 1
},
{
b: 2
}
]);
t.end();
});
});