Skip to content

Commit 8924083

Browse files
Ruby: Fixed CodeQL polynomial regexp (#18699)
1 parent e9f961e commit 8924083

File tree

11 files changed

+22
-22
lines changed

11 files changed

+22
-22
lines changed

modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module {{moduleName}}
6464
# @param [String] mime MIME
6565
# @return [Boolean] True if the MIME is application/json
6666
def json_mime?(mime)
67-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
67+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
6868
end
6969

7070
# Deserialize the response to the given return type.
@@ -143,7 +143,7 @@ module {{moduleName}}
143143
# @param [String] filename the filename to be sanitized
144144
# @return [String] the sanitized filename
145145
def sanitize_filename(filename)
146-
filename.gsub(/.*[\/\\]/, '')
146+
filename.split(/[\/\\]/).last
147147
end
148148

149149
def build_request_url(path, opts = {})

samples/client/echo_api/ruby-faraday/lib/openapi_client/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def basic_auth(conn)
249249
# @param [String] mime MIME
250250
# @return [Boolean] True if the MIME is application/json
251251
def json_mime?(mime)
252-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
252+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
253253
end
254254

255255
# Deserialize the response to the given return type.
@@ -328,7 +328,7 @@ def convert_to_type(data, return_type)
328328
# @param [String] filename the filename to be sanitized
329329
# @return [String] the sanitized filename
330330
def sanitize_filename(filename)
331-
filename.gsub(/.*[\/\\]/, '')
331+
filename.split(/[\/\\]/).last
332332
end
333333

334334
def build_request_url(path, opts = {})

samples/client/echo_api/ruby-httpx/lib/openapi_client/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def session
188188
# @param [String] mime MIME
189189
# @return [Boolean] True if the MIME is application/json
190190
def json_mime?(mime)
191-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
191+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
192192
end
193193

194194
# Deserialize the response to the given return type.
@@ -267,7 +267,7 @@ def convert_to_type(data, return_type)
267267
# @param [String] filename the filename to be sanitized
268268
# @return [String] the sanitized filename
269269
def sanitize_filename(filename)
270-
filename.gsub(/.*[\/\\]/, '')
270+
filename.split(/[\/\\]/).last
271271
end
272272

273273
def build_request_url(path, opts = {})

samples/client/echo_api/ruby-typhoeus/lib/openapi_client/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def download_file(request)
212212
# @param [String] mime MIME
213213
# @return [Boolean] True if the MIME is application/json
214214
def json_mime?(mime)
215-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
215+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
216216
end
217217

218218
# Deserialize the response to the given return type.
@@ -291,7 +291,7 @@ def convert_to_type(data, return_type)
291291
# @param [String] filename the filename to be sanitized
292292
# @return [String] the sanitized filename
293293
def sanitize_filename(filename)
294-
filename.gsub(/.*[\/\\]/, '')
294+
filename.split(/[\/\\]/).last
295295
end
296296

297297
def build_request_url(path, opts = {})

samples/client/petstore/ruby-autoload/lib/petstore/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def download_file(request)
212212
# @param [String] mime MIME
213213
# @return [Boolean] True if the MIME is application/json
214214
def json_mime?(mime)
215-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
215+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
216216
end
217217

218218
# Deserialize the response to the given return type.
@@ -291,7 +291,7 @@ def convert_to_type(data, return_type)
291291
# @param [String] filename the filename to be sanitized
292292
# @return [String] the sanitized filename
293293
def sanitize_filename(filename)
294-
filename.gsub(/.*[\/\\]/, '')
294+
filename.split(/[\/\\]/).last
295295
end
296296

297297
def build_request_url(path, opts = {})

samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def basic_auth(conn)
249249
# @param [String] mime MIME
250250
# @return [Boolean] True if the MIME is application/json
251251
def json_mime?(mime)
252-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
252+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
253253
end
254254

255255
# Deserialize the response to the given return type.
@@ -328,7 +328,7 @@ def convert_to_type(data, return_type)
328328
# @param [String] filename the filename to be sanitized
329329
# @return [String] the sanitized filename
330330
def sanitize_filename(filename)
331-
filename.gsub(/.*[\/\\]/, '')
331+
filename.split(/[\/\\]/).last
332332
end
333333

334334
def build_request_url(path, opts = {})

samples/client/petstore/ruby-httpx/lib/petstore/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def session
188188
# @param [String] mime MIME
189189
# @return [Boolean] True if the MIME is application/json
190190
def json_mime?(mime)
191-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
191+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
192192
end
193193

194194
# Deserialize the response to the given return type.
@@ -267,7 +267,7 @@ def convert_to_type(data, return_type)
267267
# @param [String] filename the filename to be sanitized
268268
# @return [String] the sanitized filename
269269
def sanitize_filename(filename)
270-
filename.gsub(/.*[\/\\]/, '')
270+
filename.split(/[\/\\]/).last
271271
end
272272

273273
def build_request_url(path, opts = {})

samples/client/petstore/ruby/lib/petstore/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def download_file(request)
212212
# @param [String] mime MIME
213213
# @return [Boolean] True if the MIME is application/json
214214
def json_mime?(mime)
215-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
215+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
216216
end
217217

218218
# Deserialize the response to the given return type.
@@ -291,7 +291,7 @@ def convert_to_type(data, return_type)
291291
# @param [String] filename the filename to be sanitized
292292
# @return [String] the sanitized filename
293293
def sanitize_filename(filename)
294-
filename.gsub(/.*[\/\\]/, '')
294+
filename.split(/[\/\\]/).last
295295
end
296296

297297
def build_request_url(path, opts = {})

samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def download_file(request)
212212
# @param [String] mime MIME
213213
# @return [Boolean] True if the MIME is application/json
214214
def json_mime?(mime)
215-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
215+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
216216
end
217217

218218
# Deserialize the response to the given return type.
@@ -291,7 +291,7 @@ def convert_to_type(data, return_type)
291291
# @param [String] filename the filename to be sanitized
292292
# @return [String] the sanitized filename
293293
def sanitize_filename(filename)
294-
filename.gsub(/.*[\/\\]/, '')
294+
filename.split(/[\/\\]/).last
295295
end
296296

297297
def build_request_url(path, opts = {})

samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def download_file(request)
211211
# @param [String] mime MIME
212212
# @return [Boolean] True if the MIME is application/json
213213
def json_mime?(mime)
214-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
214+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
215215
end
216216

217217
# Deserialize the response to the given return type.
@@ -290,7 +290,7 @@ def convert_to_type(data, return_type)
290290
# @param [String] filename the filename to be sanitized
291291
# @return [String] the sanitized filename
292292
def sanitize_filename(filename)
293-
filename.gsub(/.*[\/\\]/, '')
293+
filename.split(/[\/\\]/).last
294294
end
295295

296296
def build_request_url(path, opts = {})

samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def download_file(request)
211211
# @param [String] mime MIME
212212
# @return [Boolean] True if the MIME is application/json
213213
def json_mime?(mime)
214-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
214+
(mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
215215
end
216216

217217
# Deserialize the response to the given return type.
@@ -290,7 +290,7 @@ def convert_to_type(data, return_type)
290290
# @param [String] filename the filename to be sanitized
291291
# @return [String] the sanitized filename
292292
def sanitize_filename(filename)
293-
filename.gsub(/.*[\/\\]/, '')
293+
filename.split(/[\/\\]/).last
294294
end
295295

296296
def build_request_url(path, opts = {})

0 commit comments

Comments
 (0)