Skip to content

Commit

Permalink
fix: resolved issue causing the same module to be loaded twice when l…
Browse files Browse the repository at this point in the history
…oaded once with the full path and once with only the package path
  • Loading branch information
jacopodl committed Jun 7, 2024
1 parent ceec26a commit ec79d20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion argon/vm/datatype/arobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ const TypeInfo TypeTrait = {
nullptr,
nullptr,
nullptr,
nullptr,
type_compare,
nullptr,
nullptr,
nullptr,
Expand Down
24 changes: 24 additions & 0 deletions argon/vm/importer/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,30 @@ String *SanitizeModulePath(String *name, const String *path_sep) {

Release(altsep);

auto last_sep = StringRFind(res, path_sep);
if (last_sep < 0)
return res;

auto mname_length = ARGON_RAW_STRING_LENGTH(res) - (last_sep + 1);
if (mname_length >= ARGON_RAW_STRING_LENGTH(res) - mname_length)
return res;

auto ok = argon::vm::memory::MemoryCompare(
(ARGON_RAW_STRING(name) + last_sep) - mname_length,
(ARGON_RAW_STRING(name) + last_sep + 1),
mname_length);

if (ok == 0) {
if ((name = StringSubs(res, 0, last_sep)) == nullptr) {
Release(res);
return nullptr;
}

Release(res);

return name;
}

return res;
}

Expand Down

0 comments on commit ec79d20

Please sign in to comment.