Class: AdLocalize::Sanitizers::IOSSanitizer
- Inherits:
-
Object
- Object
- AdLocalize::Sanitizers::IOSSanitizer
- Defined in:
- lib/ad_localize/sanitizers/ios_sanitizer.rb
Instance Attribute Summary collapse
-
#should_auto_escape_percent ⇒ Object
Returns the value of attribute should_auto_escape_percent.
Instance Method Summary collapse
-
#initialize ⇒ IOSSanitizer
constructor
A new instance of IOSSanitizer.
- #sanitize(value:) ⇒ Object
Constructor Details
#initialize ⇒ IOSSanitizer
Returns a new instance of IOSSanitizer.
7 8 9 |
# File 'lib/ad_localize/sanitizers/ios_sanitizer.rb', line 7 def initialize @should_auto_escape_percent = false end |
Instance Attribute Details
#should_auto_escape_percent ⇒ Object
Returns the value of attribute should_auto_escape_percent.
5 6 7 |
# File 'lib/ad_localize/sanitizers/ios_sanitizer.rb', line 5 def should_auto_escape_percent @should_auto_escape_percent end |
Instance Method Details
#sanitize(value:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ad_localize/sanitizers/ios_sanitizer.rb', line 11 def sanitize(value:) return if value.blank? processed_value = value.gsub(/(?<!\\)\"/, "\\\"") if @should_auto_escape_percent # we should escape % sign when not used as formatting function (see: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html) processed_value = processed_value.gsub(/%(?!((\d+\$)?([a-zA-Z]|@)))/, '%%') end processed_value end |