Skip to content

Commit 1d48f6d

Browse files
gh-28: Canonicalize IMPORT path resolution.
1 parent 217295a commit 1d48f6d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/interpreter.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2305,7 +2305,18 @@ void interpreter_init(Interpreter* interp, const char* source_path) {
23052305
ns_buffer_init();
23062306

23072307
if (source_path && source_path[0] != '\0') {
2308-
env_assign(interp->global_env, "__MODULE_SOURCE__", value_str(source_path), TYPE_STR, true);
2308+
char* canonical = NULL;
2309+
#if defined(_WIN32)
2310+
canonical = _fullpath(NULL, source_path, 0);
2311+
#else
2312+
canonical = realpath(source_path, NULL);
2313+
#endif
2314+
if (canonical) {
2315+
env_assign(interp->global_env, "__MODULE_SOURCE__", value_str(canonical), TYPE_STR, true);
2316+
free(canonical);
2317+
} else {
2318+
env_assign(interp->global_env, "__MODULE_SOURCE__", value_str(source_path), TYPE_STR, true);
2319+
}
23092320
}
23102321
}
23112322

0 commit comments

Comments
 (0)