Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import ./modulename ignores the ./ path prefix #22065

Closed
tersec opened this issue Jun 10, 2023 · 4 comments · Fixed by #22073
Closed

import ./modulename ignores the ./ path prefix #22065

tersec opened this issue Jun 10, 2023 · 4 comments · Fixed by #22073
Assignees

Comments

@tersec
Copy link
Contributor

tersec commented Jun 10, 2023

Description

import "."/tables
import ./tables

even in a directory with no tables.nim or other way of finding a tables module` to import, compiles.

https://nim-lang.org/docs/manual.html#modules-import-statement doesn't seem to explicitly document what should happen in this situation, but "." is a way of specifying a path. Indeed, attempting to import ./std/tables, for example, does not work, because it is being treated as a path, so there's an inconsistency here at least.

Nim Version

Nim Compiler Version 1.9.3 [Linux: amd64]
Compiled at 2023-06-10
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b2d77619757c73a8b14a8ccf127eaf3e630159cf
active boot switches: -d:release
Nim Compiler Version 1.6.12 [Linux: amd64]
Compiled at 2023-06-08
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 1aa9273640c0c51486cf3a7b67282fe58f360e91
active boot switches: -d:release

Current Output

/tmp/b.nim(2, 8) Hint: duplicate import of 'tables'; previous import here: /tmp/b.nim(1, 11) [DuplicateModuleImport]
/tmp/b.nim(1, 11) Warning: imported and not used: 'tables' [UnusedImport]
/tmp/b.nim(2, 8) Warning: imported and not used: 'tables' [UnusedImport]

Expected Output

Error: cannot open file: tables

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Jun 10, 2023

I think there is no special casing for relative paths, it just checks path / importedPath for every path supplied by --path:

import ../sugar # compiles because of lib/pure/collections/../sugar
import ../tables # fails

There might be related issues here or in https://github.com/nim-lang/RFCs with the keyword "relative"

@tersec
Copy link
Contributor Author

tersec commented Jun 10, 2023

Yeah, generally related RFCs:

@arnetheduck
Copy link
Contributor

arnetheduck commented Jun 10, 2023

+1 on this, . and other explicitly relative paths should not resolve in random locations .. this also opens for including nastiness like ../../etc/passwd and other security-sensitive files

@Araq
Copy link
Member

Araq commented Jun 11, 2023

That's the final thing I wanted to do for 2.0.

@ringabout ringabout self-assigned this Jun 11, 2023
Araq pushed a commit that referenced this issue Jun 13, 2023
* fixes #22065; do not search path for "./"

* simplify

* fixes

* fixes

* allow ".."

* cleanup

* add a test case

* slightly modify the import

* adds a changelog
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…ng#22073)

* fixes nim-lang#22065; do not search path for "./"

* simplify

* fixes

* fixes

* allow ".."

* cleanup

* add a test case

* slightly modify the import

* adds a changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants