Module: Writexlsx::Utility::Url

Included in:
ObjectPositioning, Worksheet::Hyperlink
Defined in:
lib/write_xlsx/utility/url.rb

Instance Method Summary collapse

Instance Method Details

#escape_url(url) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/write_xlsx/utility/url.rb', line 7

def escape_url(url)
  unless url =~ /%[0-9a-fA-F]{2}/
    # Escape the URL escape symbol.
    url = url.gsub("%", "%25")

    # Escape whitespae in URL.
    url = url.gsub(/[\s\x00]/, '%20')

    # Escape other special characters in URL.
    re = /(["<>\[\]`^{}])/
    while re =~ url
      match = $LAST_MATCH_INFO[1]
      url = url.sub(re, sprintf("%%%x", match.ord))
    end
  end

  url
end