lean4-htt/tests/lean/run/ioNulBytes.lean
Rob23oba d817fb0ef3
fix: handle NUL bytes in IO functions (#9616)
This PR introduces checks to make sure that the IO functions produce
errors when inputs contain NUL bytes (instead of ignoring everything
after the first NUL byte).
2025-08-01 06:12:53 +00:00

30 lines
902 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-!
# Test that IO functions error when inputs contain NUL bytes
-/
def checkError (x : IO α) : IO Unit := do
try
discard x
throw (.userError "error expected")
catch e =>
unless e matches .invalidArgument .. do
throw e
def badPath : System.FilePath := "Path with\x00NUL"
#eval checkError <| IO.setAccessRights badPath {}
#eval checkError <| IO.FS.Handle.mk badPath .read
#eval checkError <| IO.FS.realPath badPath
#eval checkError <| badPath.readDir
#eval checkError <| badPath.metadata
#eval checkError <| badPath.symlinkMetadata
#eval checkError <| IO.FS.createDir badPath
#eval checkError <| IO.FS.createDirAll badPath
#eval checkError <| IO.FS.removeDir badPath
#eval checkError <| IO.FS.removeDirAll badPath
#eval checkError <| IO.FS.removeFile badPath
#eval checkError <| IO.FS.rename badPath badPath
/-- info: none -/
#guard_msgs in
#eval IO.getEnv "Path with\x00NUL"