From e028990013b44ca9503783b16d61e72f6217ec40 Mon Sep 17 00:00:00 2001 From: Julian Speckmann <176780813+KingIronMan2011@users.noreply.github.com> Date: Wed, 29 Jul 2026 20:14:13 +0200 Subject: [PATCH] fix: improve YAML configuration handling and add normalization script --- scripts/commands/developer/export.sh | 7 ++++- scripts/commands/extensions/install.sh | 12 +++++++- scripts/commands/extensions/remove.sh | 12 +++++++- scripts/helpers/normalize-conf-yaml.js | 38 ++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 scripts/helpers/normalize-conf-yaml.js diff --git a/scripts/commands/developer/export.sh b/scripts/commands/developer/export.sh index 89b29604..8d8db556 100644 --- a/scripts/commands/developer/export.sh +++ b/scripts/commands/developer/export.sh @@ -17,6 +17,11 @@ Command() { cp -r dev/* tmp/ cd tmp || cdhalt + if ! node "$FOLDER/scripts/helpers/normalize-conf-yaml.js" conf.yml; then + PRINT FATAL "Unable to normalize extension configuration to UTF-8." + return 1 + fi + # Assign variables to extension flags. flags="$conf_info_flags" PRINT INFO "Reading and assigning extension flags.." @@ -76,4 +81,4 @@ Command() { else PRINT SUCCESS "Extension has been exported to '${FOLDER}/${identifier}.blueprint'." fi -} \ No newline at end of file +} diff --git a/scripts/commands/extensions/install.sh b/scripts/commands/extensions/install.sh index 71ada1c4..90af9bb9 100644 --- a/scripts/commands/extensions/install.sh +++ b/scripts/commands/extensions/install.sh @@ -148,7 +148,17 @@ InstallExtension() { return 1 fi - eval "$(parse_yaml .blueprint/extensions/"${identifier}"/private/.store/conf.yml old_)" + while IFS= read -r assignment; do + if [[ -z "$assignment" ]]; then + continue + fi + + if [[ $assignment =~ ^old_[a-zA-Z0-9_]*= ]]; then + eval "$assignment" + else + PRINT WARNING "Ignoring malformed stored extension configuration entry while updating '$identifier'." + fi + done < <(parse_yaml ".blueprint/extensions/${identifier}/private/.store/conf.yml" old_) local DUPLICATE="y" # run extension update script diff --git a/scripts/commands/extensions/remove.sh b/scripts/commands/extensions/remove.sh index 40ccb54d..1ec8ad2a 100644 --- a/scripts/commands/extensions/remove.sh +++ b/scripts/commands/extensions/remove.sh @@ -30,7 +30,17 @@ RemoveExtension() { ((PROGRESS_NOW++)) if [[ -f ".blueprint/extensions/$EXTENSION/private/.store/conf.yml" ]]; then - eval "$(parse_yaml ".blueprint/extensions/$EXTENSION/private/.store/conf.yml" conf_)" + while IFS= read -r assignment; do + if [[ -z "$assignment" ]]; then + continue + fi + + if [[ $assignment =~ ^conf_[a-zA-Z0-9_]*= ]]; then + eval "$assignment" + else + PRINT WARNING "Ignoring malformed stored extension configuration entry while removing '$EXTENSION'." + fi + done < <(parse_yaml ".blueprint/extensions/${EXTENSION}/private/.store/conf.yml" conf_) # Add aliases for config values to make working with them easier. local name="${conf_info_name//&/\\&}" local identifier="${conf_info_identifier//&/\\&}" diff --git a/scripts/helpers/normalize-conf-yaml.js b/scripts/helpers/normalize-conf-yaml.js new file mode 100644 index 00000000..88194e2f --- /dev/null +++ b/scripts/helpers/normalize-conf-yaml.js @@ -0,0 +1,38 @@ +const fs = require('fs'); + +const path = process.argv[2]; + +if (!path) { + console.error('Usage: node normalize-conf-yaml.js '); + process.exit(1); +} + +let contents; + +try { + contents = fs.readFileSync(path); +} catch { + console.error(`Unable to read ${path}.`); + process.exit(1); +} + +let encoding = 'utf-8'; +let offset = 0; + +if (contents.subarray(0, 3).equals(Buffer.from([0xef, 0xbb, 0xbf]))) { + offset = 3; +} else if (contents.subarray(0, 2).equals(Buffer.from([0xff, 0xfe]))) { + encoding = 'utf-16le'; + offset = 2; +} else if (contents.subarray(0, 2).equals(Buffer.from([0xfe, 0xff]))) { + encoding = 'utf-16be'; + offset = 2; +} + +try { + const text = new TextDecoder(encoding, { fatal: true }).decode(contents.subarray(offset)); + fs.writeFileSync(path, text, 'utf8'); +} catch { + console.error(`Unable to convert ${path} to UTF-8.`); + process.exit(1); +}