Class: UTF8Cleaner::URIString

Inherits:
Object
  • Object
show all
Defined in:
lib/utf8-cleaner/uri_string.rb

Overview

Cleans invalid %-encodings from URI-encoded strings.

Constant Summary collapse

HEX_CHARS =
'0-9a-fA-F'
HEX_CHARS_REGEX =
/[#{HEX_CHARS}]/
INVALID_PERCENT_ENCODING_REGEX =
/%(?![#{HEX_CHARS}]{2})/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ URIString

Returns a new instance of URIString.



10
11
12
# File 'lib/utf8-cleaner/uri_string.rb', line 10

def initialize(data)
  self.data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/utf8-cleaner/uri_string.rb', line 4

def data
  @data
end

Instance Method Details

#cleanedObject



14
15
16
17
18
19
20
# File 'lib/utf8-cleaner/uri_string.rb', line 14

def cleaned
  if valid?
    data
  else
    encoded_char_array.join
  end
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/utf8-cleaner/uri_string.rb', line 22

def valid?
  valid_uri_encoded_utf8(data)
end