The problem is that on Windows API, to keep combability with previous versions, the maximum length for a full file name is 255 (may be a little less).
The a directory is being created relative to C:\Users\nil\Downloads\sanitize\temp, so the full file name is C:\Users\nil\Downloads\sanitize\temp\a\408_-IMG SRC=javascript:alert('XSS')-. This is 261 characters long. that is the reason to your program fail. There are ways to overcome this limit that are documented on https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation. One of them is prefix your file name with \\?\, but you must use the complete file name, not a relative one like you used. The other is enabling long file names on windows and embed a manifest on your program. On Thursday, October 15, 2020 at 7:57:09 PM UTC-3, nilsocket wrote: > > var fileName = `408_-IMG > SRC=javascript:alert('XSS')-` > var dir1 = "a" > > func main() { > createFile(dir1, fileName) // not working, any dir not working > createFile("", fileName) // working > createFile("c", "d") // working > } > > func createFile(dir, filename string) { > os.MkdirAll(dir, os.ModePerm) > > if f, err := os.Create(filepath.Join(dir, filename)); err != nil { > log.Println(err) > } else { > f.Close() > } > } > > I was trying to create this file from yesterday, I went through windows > documentation, but not able to find any solution. > > I'm getting error: Linked picture > > Filename length is 221 > With dir: 223 > It doesn't cross windows Max path length, I'm running windows 10 Home > version 1909. > It doesn't contain any invalid characters. > > It's working fine in Linux. > > If there something wrong with what I'm doing or a bug? > > > Thank you > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9479d035-103d-4a02-84c1-30fd8f729dc9o%40googlegroups.com.