From 9128e73b03856c72e90c581cb36e931e971af29e Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 2 Jan 2017 16:13:57 +0100 Subject: [PATCH 1/4] docs: clarify what are considered as absolute paths --- docs/layout-of-source-files.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst index dff48be31..1e27b7c04 100644 --- a/docs/layout-of-source-files.rst +++ b/docs/layout-of-source-files.rst @@ -79,8 +79,9 @@ Paths ----- In the above, ``filename`` is always treated as a path with ``/`` as directory separator, -``.`` as the current and ``..`` as the parent directory. Path names that do not start -with ``.`` are treated as absolute paths. +``.`` as the current and ``..`` as the parent directory. When ``.`` or ``..`` is followed by a character except ``/``, +it is not considered as the current or the parent directory. +All path names are treated as absolute paths unless they start with the current ``.`` or the parent directory ``..``. To import a file ``x`` from the same directory as the current file, use ``import "./x" as x;``. If you use ``import "x" as x;`` instead, a different file could be referenced From 41fe412389645fd423c8fb2422db99892f829030 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 2 Jan 2017 16:47:45 +0100 Subject: [PATCH 2/4] interface: change absolutePath() so that ".dir" is considered as an absolute path fixes #1534 --- libsolidity/interface/CompilerStack.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 4095844f7..ee55f41af 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -593,11 +593,11 @@ bool CompilerStack::checkLibraryNameClashes() string CompilerStack::absolutePath(string const& _path, string const& _reference) const { - // Anything that does not start with `.` is an absolute path. - if (_path.empty() || _path.front() != '.') - return _path; using path = boost::filesystem::path; path p(_path); + // Anything that does not start with `.` is an absolute path. + if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != "..")) + return _path; path result(_reference); result.remove_filename(); for (path::iterator it = p.begin(); it != p.end(); ++it) From 07f34e0023c395b43c5d63ce5a4d2cf5160025fa Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 3 Jan 2017 18:16:33 +0100 Subject: [PATCH 3/4] test: add a test importing a file name starting with a period --- test/libsolidity/Imports.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp index bc6adc265..e3f0b281b 100644 --- a/test/libsolidity/Imports.cpp +++ b/test/libsolidity/Imports.cpp @@ -164,6 +164,14 @@ BOOST_AUTO_TEST_CASE(context_dependent_remappings) BOOST_CHECK(c.compile()); } +BOOST_AUTO_TEST_CASE(filename_with_period) +{ + CompilerStack c; + c.addSource("a/a.sol", "import \".b.sol\"; contract A is B {} pragma solidity >=0.0;"); + c.addSource("a/.b.sol", "contract B {} pragma solidity >=0.0;"); + BOOST_CHECK(!c.compile()); +} + BOOST_AUTO_TEST_SUITE_END() } From 779a01faa9b18a58a133a120d6aebe1df612cb00 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 6 Jan 2017 16:21:16 +0100 Subject: [PATCH 4/4] Changelog: document #1537 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index a82e8744d..0ac0cb2f0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ BugFixes: * Type checker, code generator: enable access to events of base contracts' names. + * Imports: ``import ".dir/a"`` is not a relative path. Relative paths begin with directory ``.`` or ``..``. ### 0.4.7 (2016-12-15)