From 96f2a3469bf623e3654cf5703cd05d2939bda2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 3 Apr 2017 13:02:12 +0200 Subject: [PATCH 1/4] doc: path functions ignore trailing slashes Add notes about path.parse(), path.basename() and path.dirname() ignoring trailing slashes. Refs: https://github.com/nodejs/node/issues/6229 --- doc/api/path.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/api/path.md b/doc/api/path.md index 0039e2c3ef14bd..73fbeebaf8e535 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -68,7 +68,8 @@ changes: * Returns: {string} The `path.basename()` methods returns the last portion of a `path`, similar to -the Unix `basename` command. +the Unix `basename` command. Conforming to Posix standards, trailing `/` +characters are not counted as part of the pathname. For example: @@ -128,7 +129,8 @@ changes: * Returns: {string} The `path.dirname()` method returns the directory name of a `path`, similar to -the Unix `dirname` command. +the Unix `dirname` command. Conforming to Posix standards, trailing `/` +characters are not counted as part of the pathname. For example: @@ -347,7 +349,8 @@ added: v0.11.15 * Returns: {Object} The `path.parse()` method returns an object whose properties represent -significant elements of the `path`. +significant elements of the `path`. Note that trailing `/` characters are not +counted as part of the pathname and therefore ignored. The returned object will have the following properties: From abb4b82989efad9b4f02cb0f697fc3e8c0f80ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 3 Apr 2017 14:16:00 +0200 Subject: [PATCH 2/4] Remove POSIX reference and add note about Windows --- doc/api/path.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/path.md b/doc/api/path.md index 73fbeebaf8e535..68c17218b8e033 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -68,8 +68,8 @@ changes: * Returns: {string} The `path.basename()` methods returns the last portion of a `path`, similar to -the Unix `basename` command. Conforming to Posix standards, trailing `/` -characters are not counted as part of the pathname. +the Unix `basename` command. Trailing `/` (and `\\` on Windows) characters are +ignored. For example: @@ -129,8 +129,8 @@ changes: * Returns: {string} The `path.dirname()` method returns the directory name of a `path`, similar to -the Unix `dirname` command. Conforming to Posix standards, trailing `/` -characters are not counted as part of the pathname. +the Unix `dirname` command. Trailing `/` (and `\\` on Windows) characters are +ignored. For example: @@ -349,8 +349,8 @@ added: v0.11.15 * Returns: {Object} The `path.parse()` method returns an object whose properties represent -significant elements of the `path`. Note that trailing `/` characters are not -counted as part of the pathname and therefore ignored. +significant elements of the `path`. Trailing `/` (and `\\` on Windows) +characters are ignored. The returned object will have the following properties: From 879ef35ab715e614bad984848c1865f56d068c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Wed, 5 Apr 2017 11:34:49 +0200 Subject: [PATCH 3/4] Clarify differences between Windows and POSIX --- doc/api/path.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/api/path.md b/doc/api/path.md index 68c17218b8e033..70663ee0468e4b 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -68,8 +68,8 @@ changes: * Returns: {string} The `path.basename()` methods returns the last portion of a `path`, similar to -the Unix `basename` command. Trailing `/` (and `\\` on Windows) characters are -ignored. +the Unix `basename` command. Trailing directory separators are ignored, see +[`path.sep`][]. For example: @@ -129,8 +129,8 @@ changes: * Returns: {string} The `path.dirname()` method returns the directory name of a `path`, similar to -the Unix `dirname` command. Trailing `/` (and `\\` on Windows) characters are -ignored. +the Unix `dirname` command. Trailing directory separators are ignored, see +[`path.sep`][]. For example: @@ -349,8 +349,8 @@ added: v0.11.15 * Returns: {Object} The `path.parse()` method returns an object whose properties represent -significant elements of the `path`. Trailing `/` (and `\\` on Windows) -characters are ignored. +significant elements of the `path`. Trailing directory separators are ignored, +see [`path.sep`][]. The returned object will have the following properties: @@ -526,6 +526,11 @@ On Windows: // Returns: ['foo', 'bar', 'baz'] ``` +*Note*: On Windows, both the forward slash (`/`) and backward slash (`\`) are +accepted as path segment separators; however, if separators are to be added by +Windows-specific implementations of the `path` methods, only the backward slash +(`\`) will be used. + ## path.win32