aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-01-07 00:11:10 +0800
committerGitHub <noreply@github.com>2017-01-07 00:11:10 +0800
commita4d7a590ea0a38c3418cca50192e5fcedf38a8fb (patch)
tree55be823aa5a97e22756ef2498299703cff73698b
parent0031e6a530a12d98752a1ad85750f25c9890a6ba (diff)
parent779a01faa9b18a58a133a120d6aebe1df612cb00 (diff)
downloaddexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar.gz
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar.bz2
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar.lz
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar.xz
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.tar.zst
dexon-solidity-a4d7a590ea0a38c3418cca50192e5fcedf38a8fb.zip
Merge pull request #1537 from ethereum/absolute-path
absolute path detection is not confused by ".dir"
-rw-r--r--Changelog.md1
-rw-r--r--docs/layout-of-source-files.rst5
-rw-r--r--libsolidity/interface/CompilerStack.cpp6
-rw-r--r--test/libsolidity/Imports.cpp8
4 files changed, 15 insertions, 5 deletions
diff --git a/Changelog.md b/Changelog.md
index a82e8744..0ac0cb2f 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)
diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst
index dff48be3..1e27b7c0 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
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 4095844f..ee55f41a 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)
diff --git a/test/libsolidity/Imports.cpp b/test/libsolidity/Imports.cpp
index bc6adc26..e3f0b281 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()
}