Skip to content

Commit 3bcb05f

Browse files
committed
refactor(metrics): enhance UTF-8 URL encoding and parsing methods with improved handling for spaces and special characters for Ukrainian utf-8 urls
1 parent 4ad463c commit 3bcb05f

File tree

3 files changed

+381
-5
lines changed

3 files changed

+381
-5
lines changed

.env.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
ALLOWED_HOSTS='http://localhost:3000'
77
APP_HOST='http://localhost:3000'
88
APP_DEFAULT_LOCALE='en'
9-
APP_AVAILABLE_LOCALES='es,en,fr'
10-
APP_FALLBACK_LOCALES='es,en,fr'
9+
APP_AVAILABLE_LOCALES='es,en,fr,uk'
10+
APP_FALLBACK_LOCALES='es,en,fr,uk'
1111

1212
ES_PORT='9200'
1313
ES_HOST='http://elasticsearch'

app/models/concerns/better_together/metrics/utf8_url_handler.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ def encode_utf8_url(url) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength, M
6363
# @param component [String] The URL component to encode
6464
# @return [String] Encoded component
6565
def encode_utf8_component(component)
66-
return component if component.blank?
66+
return '' if component.nil? || component.empty?
6767

68-
# Only encode non-ASCII characters
69-
component.gsub(/[^\x00-\x7F]/) { |char| CGI.escape(char) }
68+
# Encode spaces and non-ASCII characters
69+
# Use URI encoding which properly encodes spaces as %20
70+
component.gsub(/\s|[^\x00-\x7F]/) do |char|
71+
if char == ' '
72+
'%20'
73+
else
74+
char.bytes.map { |b| format('%%%02X', b) }.join
75+
end
76+
end
7077
end
7178

7279
# Encode UTF-8 characters in a host component (for IDN support)

0 commit comments

Comments
 (0)