jbe/bsw@0: --[[-- jbe/bsw@0: encoded_path_element = -- string which can't contain evil stuff like "/" jbe/bsw@0: encode.file_path_element( jbe/bsw@0: path_element -- string to be encoded jbe/bsw@0: ) jbe/bsw@0: jbe/bsw@0: This function is encoding a string in a way that it can be used as a file or directory name, without security risks. See the source for details. jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function encode.file_path_element(path_element) jbe/bsw@0: return ( jbe/bsw@0: string.gsub( jbe/bsw@0: string.gsub( jbe/bsw@0: path_element, "[^0-9A-Za-z_%.-]", jbe/bsw@0: function(char) jbe/bsw@0: return string.format("%%%02x", string.byte(char)) jbe/bsw@0: end jbe/bsw@0: ), "^%.", string.format("%%%%%02x", string.byte(".")) jbe/bsw@0: ) jbe/bsw@0: ) jbe/bsw@0: end