Skip to content

Commit efc11a8

Browse files
authored
Merge pull request #13572 from ethereum/docs-clarify-relative-path-normalization
[Docs] Clarify relative path normalization rules
2 parents 5ca2ca3 + 1df95ed commit efc11a8

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

docs/path-resolution.rst

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ source unit name.
197197

198198
A source unit name is just an identifier and even if its value happens to look like a path, it
199199
is not subject to the normalization rules you would typically expect in a shell.
200-
Any ``/./`` or ``/../`` seguments or sequences of multiple slashes remain a part of it.
200+
Any ``/./`` or ``/../`` segments or sequences of multiple slashes remain a part of it.
201201
When the source is provided via Standard JSON interface it is entirely possible to associate
202202
different content with source unit names that would refer to the same file on disk.
203203

@@ -248,34 +248,25 @@ and is bounded by two path separators.
248248
A separator is a forward slash or the beginning/end of the string.
249249
For example in ``./abc/..//`` there are three path segments: ``.``, ``abc`` and ``..``.
250250

251-
The compiler computes a source unit name from the import path in the following way:
251+
The compiler resolves the import into a source unit name based on the import path, in the following way:
252252

253-
1. First a prefix is computed
254-
255-
- Prefix is initialized with the source unit name of the importing source unit.
256-
- The last path segment with preceding slashes is removed from the prefix.
257-
- Then, the leading part of the normalized import path, consisting only of ``/`` and ``.``
258-
characters is considered.
259-
For every ``..`` segment found in this part the last path segment with preceding slashes is
260-
removed from the prefix.
261-
262-
2. Then the prefix is prepended to the normalized import path.
263-
If the prefix is non-empty, a single slash is inserted between it and the import path.
253+
#. We start with the source unit name of the importing source unit.
254+
#. The last path segment with preceding slashes is removed from the resolved name.
255+
#. Then, for every segment in the import path, starting from the leftmost one:
256+
- If the segment is ``.``, it is skipped.
257+
- If the segment is ``..``, the last path segment with preceding slashes is removed from the resolved name.
258+
- Otherwise, the segment (preceded by a single slash if the resolved name is not empty), is appended to the resolved name.
264259

265260
The removal of the last path segment with preceding slashes is understood to
266261
work as follows:
267262

268263
1. Everything past the last slash is removed (i.e. ``a/b//c.sol`` becomes ``a/b//``).
269264
2. All trailing slashes are removed (i.e. ``a/b//`` becomes ``a/b``).
270265

271-
The normalization rules are the same as for UNIX paths, namely:
272-
273-
- All the internal ``.`` segments are removed.
274-
- Every internal ``..`` segment backtracks one level up in the hierarchy.
275-
- Multiple slashes are squashed into a single one.
276-
277-
Note that normalization is performed only on the import path.
278-
The source unit name of the importing module that is used for the prefix remains unnormalized.
266+
Note that the process normalizes the part of the resolved source unit name that comes from the import path according
267+
to the usual rules for UNIX paths, i.e. all ``.`` and ``..`` are removed and multiple slashes are
268+
squashed into a single one.
269+
On the other hand, the part that comes from the source unit name of the importing module remains unnormalized.
279270
This ensures that the ``protocol://`` part does not turn into ``protocol:/`` if the importing file
280271
is identified with a URL.
281272

0 commit comments

Comments
 (0)