bstraehle commited on
Commit
1584483
·
verified ·
1 Parent(s): e17063e

Update utils/utils.py

Browse files
Files changed (1) hide show
  1. utils/utils.py +8 -16
utils/utils.py CHANGED
@@ -115,23 +115,15 @@ def read_pptx_text(file_path):
115
  def validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key):
116
  is_valid = True
117
 
118
- if (question.len() > 500 or
119
- openai_api_key.len() > 150 or
120
- gemini_api_key.len() > 150 or
121
- anthropic_api_key.len() > 150):
122
  is_valid = False
123
 
124
- # Allow: letters, numbers, spaces, basic punctuation, common symbols
125
- # Block: HTML tags, script injection, control characters, etc.
126
- #temp = re.sub(r'[^\w\s.,!?\'\-()@$%&+/:;"=\[\]]', '', input_text)
127
-
128
- # Max length is MAX_LENGTH
129
- #temp = temp[:MAX_LENGTH]
130
-
131
- # Max word length is MAX_WORD_LENGTH
132
- #temp = ' '.join(word[:MAX_WORD_LENGTH] for word in temp.split(' '))
133
-
134
- # Max word count is MAX_WORD_COUNT
135
- #temp = ' '.join(temp.split(' ')[:MAX_WORD_COUNT])
136
 
137
  return is_valid
 
115
  def validate_input(question, openai_api_key, gemini_api_key, anthropic_api_key):
116
  is_valid = True
117
 
118
+ if (len(question) > 500
119
+ or len(openai_api_key) > 150
120
+ or len(gemini_api_key) > 150
121
+ or len(anthropic_api_key) > 150:
122
  is_valid = False
123
 
124
+ sanitized_question = re.sub(r'[^\w\s.,!?\'\-()@$%&+/:;"=\[\]]', '', question)
125
+
126
+ if sanitized_question != question:
127
+ is_valid = False
 
 
 
 
 
 
 
 
128
 
129
  return is_valid