This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path.join doesn't strip LF or CR
Type: behavior Stage:
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ExtraVeral, georg.brandl, pitrou, steven.daprano
Priority: normal Keywords:

Created on 2014-02-24 14:10 by ExtraVeral, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg212099 - (view) Author: Tiberiu Dragulinescu (ExtraVeral) Date: 2014-02-24 14:10
>>>d="asdasd"+chr(10)
>>>print os.path.normpath(os.path.join('a/b',d,'d'))
a\b\asdasd
\d

LF or CR cannot be part of a URI (rfc1738)
msg212106 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2014-02-24 15:03
> LF or CR cannot be part of a URI

But they can be part of a filename, at least on POSIX systems. Are you proposing that only the Windows version of os.path.join strip LF/CR? 

I don't think that it up to the join function to validate the path, and certainly not to modify the substrings. Would you expect it to complain about this? os.path.join('/', 'AUX')? (AUX is a reserved name and forbidden for file names under Windows.)

I don't think it is up to join to validate that the path generated is legal, so I don't think this is a bug in join.
msg212109 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-24 15:49
This doesn't sound like a bug. File paths are not URIs: almost all characters are valid in a POSIX filename. Also, sanity checking of user input is up to the caller.

I recommend closing this issue.
msg212110 - (view) Author: Tiberiu Dragulinescu (ExtraVeral) Date: 2014-02-24 15:51
The join function should know that it will compose a path with the provided
string, so I think it should complain or ignore ilegal path/filename
components, in regard to the host OS.

But if it is not a valid point of view python-wise, one can check his own
path :P

On Mon, Feb 24, 2014 at 4:03 PM, Steven D'Aprano <report@bugs.python.org>wrote:

>
> Steven D'Aprano added the comment:
>
> > LF or CR cannot be part of a URI
>
> But they can be part of a filename, at least on POSIX systems. Are you
> proposing that only the Windows version of os.path.join strip LF/CR?
>
> I don't think that it up to the join function to validate the path, and
> certainly not to modify the substrings. Would you expect it to complain
> about this? os.path.join('/', 'AUX')? (AUX is a reserved name and forbidden
> for file names under Windows.)
>
> I don't think it is up to join to validate that the path generated is
> legal, so I don't think this is a bug in join.
>
> ----------
> nosy: +stevenjd
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue20761>
> _______________________________________
>
msg212865 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-03-07 09:16
Agreed.
History
Date User Action Args
2022-04-11 14:57:59adminsetgithub: 64960
2014-03-07 09:16:22georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
messages: + msg212865

2014-02-24 15:51:29ExtraVeralsetmessages: + msg212110
2014-02-24 15:49:01pitrousetresolution: not a bug

messages: + msg212109
nosy: + pitrou
2014-02-24 15:03:12steven.dapranosetnosy: + steven.daprano
messages: + msg212106
2014-02-24 14:10:29ExtraVeralcreate