2022-12-31 03:08:02 +01:00
|
|
|
# utilities to prevent malicious user input
|
|
|
|
module CrystalGauntlet::Clean
|
|
|
|
extend self
|
|
|
|
|
|
|
|
# for descriptions & similar
|
2023-01-04 12:55:59 +01:00
|
|
|
def clean_special(str : String)
|
2022-12-31 03:08:02 +01:00
|
|
|
str.gsub(/[\0]/, "")
|
|
|
|
end
|
|
|
|
|
|
|
|
# only allow alphanumeric chars & space
|
|
|
|
def clean_char(str)
|
|
|
|
str.gsub(/[^A-Za-z0-9 ]/, "")
|
|
|
|
end
|
|
|
|
|
2022-12-31 20:05:39 +01:00
|
|
|
# only allow "basic" characters (roughly printable ascii, excluding format-breaking chars)
|
|
|
|
def clean_basic(str)
|
|
|
|
str.gsub(/[^A-Za-z0-9\-_ ]/, "")
|
|
|
|
end
|
|
|
|
|
2022-12-31 03:08:02 +01:00
|
|
|
# only allows numbers
|
|
|
|
def clean_number(str)
|
|
|
|
str.gsub(/[^0-9]/, "")
|
|
|
|
end
|
|
|
|
|
|
|
|
# for b64 inputs; thoroughly cleans them
|
|
|
|
def clean_b64(str)
|
2023-01-03 11:38:23 +01:00
|
|
|
Base64.urlsafe_encode(Base64.decode_string(str))
|
2022-12-31 03:08:02 +01:00
|
|
|
end
|
|
|
|
end
|