5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ad_localize/sanitizers/ios_to_android_sanitizer.rb', line 5
def sanitize(value:)
return if value.blank?
processedValue = value.gsub(/(?<!\\)'/, ''') processedValue = processedValue.gsub(/(?<!\\)\"/, '"') processedValue = processedValue.gsub(">", '>')
processedValue = processedValue.gsub("<", '<')
hasFormatting = processedValue.match(/(%(\d+\$)?@)/)
processedValue = processedValue.gsub(/(%(\d+\$)?@)/, '%\2s') hasFormatting = hasFormatting || processedValue.match(/(%((\d+\$)?(\d+)?)i)/)
processedValue = processedValue.gsub(/(%((\d+\$)?(\d+)?)i)/, '%\2d') if hasFormatting
processedValue = processedValue.gsub(/%(?!((\d+\$)?(s|(\d+)?d)))/, '%%') else
processedValue = processedValue.gsub(/%(?!((\d+\$)?(s|(\d+)?d)))/, '%') end
processedValue = processedValue.gsub("\\U", "\\u")
processedValue = processedValue.gsub(/&(?!((#\d+)|(\w+));)/, '&')
processedValue = processedValue.gsub(/&/) { |match| match.replace('\&') }
"\"#{processedValue}\""
end
|