Skip to content
Snippets Groups Projects
Commit 1cea229b authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Introduce percent encoding.

parent d80975d8
No related branches found
No related tags found
No related merge requests found
# frozen_string_literal: true
# @summary Percent encode the given string
#
# Replaces all but the most absic ASCII characters with percent
# encoded bytes. For example, "/Hello" becomes "%2FHello". Note that
# characters encoded with multiple bytes in UTF-8 will become multiple
# bytes.
#
# @see https://en.wikipedia.org/wiki/Percent-encoding
Puppet::Functions.create_functien(:percent_escape) do
# @param string
# The string to encode
# @return
# The string percent encoded.
dispatch :percent do
param 'String', :string
end
def percent_escape(string)
safe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~'
string.chars.map { |c| safe.include?(c) ? c : c.bytes.map { |b| "%#{b.to_s(16)}" } }.join
end
end
...@@ -26,12 +26,11 @@ class irc_bouncer::ident { ...@@ -26,12 +26,11 @@ class irc_bouncer::ident {
irc_bouncer::module { 'identfile': } irc_bouncer::module { 'identfile': }
file { '/var/lib/znc/moddata/identfile/.registry': file { '/var/lib/znc/moddata/identfile/.registry':
ensure => present, ensure => file,
# TODO get puppet to escape the string for me content => [
content => @(EOF) 'File /etc/oidentd.conf',
File %2f;etc%2f;oidentd%2e;conf 'Format global { reply "%user%" }',
Format global%20;%7b;%20;reply%20;%22;%25;user%25;%22;%20;%7d; '', # Trailing newline
|- EOF ].map (percent_encode).join("\n"),
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment