Why does System.IO.DirectoryInfo allow me to build a path ending in a form feed?

When writing some property-based tests in F #, I found very strange constructor behavior System.IO.DirectoryInfo. Based on the documentation , I would expect it to ArgumentExceptionbe thrown when trying to build DirectoryInfowith an invalid path character; and I would expect it Path.GetInvalidPathChars()to be a reliable source for them. The documentation says: "The array returned by this method will not contain the full set of characters that are not allowed in the file and directory names"; but he says nothing about the method that returns characters that are not invalid! Form feed ('\012') is one of these invalid characters, as you might expect; I would expect any control character to be invalid in the path name. And indeed, if I try to build DirectoryInfowith one in the middle or at the beginning, it will not work. However, it works if I put it at the end:

weird FSI session

The resulting absolute path has no form in it, although it confirms that this is indeed an invalid symbol of the path. I confirmed that the directory I created in this REPL session was there, with no control characters in the name. However, to make it even weirder when I convert DirectoryInfo back to a string, the garbage character is supported:

Form submission supported on .ToString ()

'\009', '\010' '\011', '\013', . , , .

? ​​ DirectoryInfo, / .NET? ( !)

+4

Source: https://habr.com/ru/post/1696365/


All Articles