Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Old script values: retry only bare names, never paths; keep the first error

islandmedede08035fe68
diff --git a/src/core/Commands.cpp b/src/core/Commands.cpp
index c165b89e..7ec5f785 100644
--- a/src/core/Commands.cpp
+++ b/src/core/Commands.cpp
@@ -53,6 +53,7 @@
#include "io/UsdIO.h"
#include <algorithm>
+#include <cctype>
#include <filesystem>
#include <glm/gtc/matrix_transform.hpp>
#include <sstream>
@@ -852,21 +853,25 @@ const Command* CommandRegistry::find(const std::string& name) const {
}
namespace {
-// Args from an older version's script: parameter names, and string values when the command refused them as they
-// were (so a user's own text is never changed when the command accepts it).
+// A value an older version's script may have used as a name (layout=..., mode=..., id=...): letters, digits, '_'
+// and '-' only, so paths and a user's own text are never rewritten.
+bool oldNameValue(const ArgValue& v) {
+ const std::string* s = std::get_if<std::string>(&v);
+ if (!s || s->empty() || s->size() > 64) return false;
+ for (unsigned char c : *s)
+ if (!std::isalnum(c) && c != '_' && c != '-') return false;
+ return legacy::isOld(*s);
+}
+// Args from an older version's script: parameter names, and (values) old name values.
Args modernizedArgs(const Args& args, bool values) {
Args out;
- for (const auto& [k, v] : args) {
- ArgValue nv = v;
- if (values)
- if (const std::string* s = std::get_if<std::string>(&v); s && legacy::isOld(*s)) nv = legacy::modernize(*s);
- out[legacy::modernize(k)] = std::move(nv);
- }
+ for (const auto& [k, v] : args)
+ out[legacy::modernize(k)] = values && oldNameValue(v) ? ArgValue(legacy::modernize(std::get<std::string>(v))) : v;
return out;
}
bool anyOldValue(const Args& args) {
for (const auto& [k, v] : args)
- if (const std::string* s = std::get_if<std::string>(&v); s && legacy::isOld(*s)) return true;
+ if (oldNameValue(v)) return true;
return false;
}
} // namespace
@@ -886,7 +891,8 @@ CommandResult CommandRegistry::execute(Document& doc, const std::string& name, c
if (doc.extractPreview.id && name.rfind("extract", 0) != 0)
doc.dropExtractPreview(!(name.rfind("save", 0) == 0 || name.rfind("export", 0) == 0));
CommandResult r = cmd->run(doc, args);
- if (!r.ok && anyOldValue(args)) r = cmd->run(doc, modernizedArgs(args, true)); // a value an older version used
+ if (!r.ok && anyOldValue(args)) // a name value an older version used: try today's; keep the first answer if it fails too
+ if (CommandResult again = cmd->run(doc, modernizedArgs(args, true)); again.ok) r = std::move(again);
if (const std::string notice = doc.takeNotice(); !notice.empty() && r.ok) r.message += ". " + notice;
return r;
}
diff --git a/tests/test_legacy_names.cpp b/tests/test_legacy_names.cpp
index 3a0c10db..cd60072c 100644
--- a/tests/test_legacy_names.cpp
+++ b/tests/test_legacy_names.cpp
@@ -88,4 +88,8 @@ TEST(legacy_names_read_old_files_and_scripts) {
Document doc;
CHECK(reg.execute(doc, old.at("part") + "_list", {}).ok);
CHECK(!reg.execute(doc, "no_such_" + old.at("part"), {}).ok);
+ // A path with an old word in it (a user's folder) is never rewritten, and a failure keeps its own message.
+ const std::string path = "/no/such/" + capitalised(old.at("classic")) + "/model.obj";
+ const CommandResult missing = reg.execute(doc, "open", {{"path", path}});
+ CHECK(!missing.ok && missing.message.find(capitalised(old.at("classic"))) != std::string::npos);
}