cartodb-4.42/lib/carto/file_system/sanitize.rb

17 lines
535 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
module Carto
module FileSystem
module Sanitize
# Sanitize: NUL, slash, backslash, colon, asterisk, question, quote, less, greater, pipe
DISALLOWED_CHARACTERS = /[\x00\/\\:\*\?\"<>\|]/
def self.sanitize_identifier(identifier, replacement_character: '_')
if replacement_character =~ DISALLOWED_CHARACTERS
raise "Unsafe replacement character '#{replacement_character}'"
else
identifier.gsub(DISALLOWED_CHARACTERS, replacement_character)
end
end
end
end
end